I want to add jcombobox to jtable please someone explain me how could i do that in netbeans
Creates a JComboBox with a default data model. The default data model is an empty list of objects. Use addItem to add items.
JComboBox inherits JComponent class .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With