How to add list boxes to Swing in a table
This article mainly shows you the "Swing in the table how to add a list box", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to add a list box in the table Swing" this article.
Swing adds drop-down list box
Swing adds a drop-down list box in a column of the table, first get the list object, set the drop-down list box to the list editing object as the default column editing object, and then set the drop-down list box to the list editing object in setting the list editing object.
Importjava.awt.BorderLayout; importjava.awt.Dimension; importjavax.swing.JFrame; importjavax.swing.JPanel; importjavax.swing.JScrollPane; importjava.awt.Rectangle; importjavax.swing.JTable; importjavax.swing.table.TableColumn; importjavax.swing.DefaultCellEditor; importjavax.swing.JComboBox; importjavax.swing.JCheckBox; publicclassJComboBoxSecondextendsJFrame {JPanelcontentPane; JScrollPanejScrollPane1=newJScrollPane () Object [] [] objContent= {{"Tom", "Hanks", "Java", "24", "true"}, {"Ben", "John", "Java", "25", "true"}, {"Michael", "Fred", "Java", "26", "true", {"Steve", "Bell", "Java", "27", "true"}, {"Jim", "Lan", "Java", "29", "true"}} Object [] objHead= {"first name", "last name", "skill", "age", "true"}; JTablejTable1=newJTable (objContent,objHead); JComboBoxjComBo=newJComboBox (); JCheckBoxjCheck=newJCheckBox ("); publicJComboBoxSecond () {try {setDefaultCloseOperation (EXIT_ON_CLOSE); jbInit ();} catch (Exceptionexception) {exception.printStackTrace ();} / * * Componentinitialization. * * @ throwsjava.lang.Exception * / privatevoidjbInit () throwsException {contentPane= (JPanel) getContentPane (); contentPane.setLayout (null); setSize (newDimension (467401)); setTitle ("FrameTitle"); jScrollPane1.setBounds (newRectangle (11mai 20442337); jComBo.addItem ("Java"); jComBo.addItem ("Orcale"); jComBo.addItem ("Linux"); jComBo.addItem ("Unix"); jComBo.addItem ("C#"); TableColumntableCol=jTable1.getColumnModel (). GetColumn (2) TableCol.setResizable (false); TableColumntableColCheck=jTable1.getColumnModel (). GetColumn (4); tableCol.setCellEditor (newDefaultCellEditor (jComBo)); tableColCheck.setCellEditor (newDefaultCellEditor (jCheck)); contentPane.add (jScrollPane1); jScrollPane1.getViewport (). Add (jTable1);}} above is all the content of the article "how to add list boxes to Swing in tables". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!