I want to add jcombobox to jtable please someone explain me how could i do that in netbeans
Asked
Active
Viewed 7,593 times
6
-
2Don't use NetBeans. Spend time learning how to write Java code yourself. Otherwise if you move to a different IDE then you will need to learn another IDE and the generated code may not be accepted by the other IDE. – camickr Jul 20 '14 at 01:18
-
Why did you post an image from [the tutorials](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#combobox) and not take the time to try something – MadProgrammer Jul 20 '14 at 03:00
-
i have tried but i can't understand how to use that tutorial in netbeans – Pasin Developer Jul 28 '14 at 20:08
1 Answers
9
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

Madhan
- 5,750
- 4
- 28
- 61
-
-
This worked for me and I will Recommend it to all people who have the same problem – Humphrey Dec 02 '17 at 10:22