Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add list boxes to Swing in a table

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report