Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add jcombobox to jtable column in netbeans

enter image description here

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

like image 769
Pasin Developer Avatar asked Jul 20 '14 01:07

Pasin Developer


People also ask

Which method is used to add items to JComboBox?

Creates a JComboBox with a default data model. The default data model is an empty list of objects. Use addItem to add items.

Which is the superclass for JComboBox?

JComboBox inherits JComponent class .


1 Answers

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

enter image description here

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

Then rightclick on JTable and click TableContents

enter image description here

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 

enter image description here

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

enter image description here

like image 52
Madhan Avatar answered Oct 11 '22 23:10

Madhan