how to add jcombobox to jtable column in netbeans

吃可爱长大的小学妹 提交于 2019-12-04 12:58:38

问题


I want to add jcombobox to jtable please someone explain me how could i do that in netbeans


回答1:


Add a JComboBox by dragging and dropping outside the frame or panel.So that it will be added to OtherComponents in the Navigator View

Add whatever contents you want to add by double clicking the combobox from Navaigator View

Then rightclick on JTable and click TableContents

In the Dialog select Columns Tab(1) and select the column(2) you want to add the combobox to.

Then Click on the button near to the Editor[Ref screenshot (3)]

Then in the editor dialog Choose Custom Code from the dropdown(4)

Then put the following(5)

new DefaultCellEditor(jComboBox1)//jComboBox1 is the variable name of combobox 

Then Click ok and close and make sure you import import javax.swing.DefaultCellEditor; or do a Ctrl+Shift+I to add the necessary imports

After that If you run and click on column 2 you'll get this output



来源:https://stackoverflow.com/questions/24846410/how-to-add-jcombobox-to-jtable-column-in-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!