How do I make an Editable JCombobox within a Table Model?

K

KLD

Within my table model , two of the columns contain a JComboBox dropdown of
choices. I want to make one of the JComboBoxes editable, jcb_Status (so you
can select from the dropdown, or type text in the field). I can only seem
to get the first row in the table model to be editable, and then it does not
put the drop down list on the subsequent items in the combobox.

Winder_Table_Model _Winder_Table_Model = null;

public void Display_Pattern_Table()
{
_Winder_Table_Model = new Winder_Table_Model();

jtbl_Positions.setModel(_Winder_Table_Model);

JComboBox jcb_Status = new JComboBox();
// I tried this, it will only make the first item editable.
// jcb_Status.setEditable(true);
_DB_Roll_status_dcd.Populate_JComboBox(jcb_Status);

// I thought maybe the setEditable only applied to the selected index and
tried this.
// It does not work either.
// int i = jcb_Status.getItemCount();
// for (int j=0 ; j < i-1 ; j++)
// {
// jcb_Status.setSelectedIndex(j);
// jcb_Status.setEditable(true);
// }

jcb_Status.setSelectedIndex(0);

JComboBox jcb_Defect = new JComboBox();
_DB_Roll_reason_cd.Populate_JComboBox(jcb_Defect);
jcb_Defect.setSelectedIndex(-1);

jtbl_Positions.getColumnModel().getColumn(6).setCellEditor(new
DefaultCellEditor(jcb_Status));
jtbl_Positions.getColumnModel().getColumn(7).setCellEditor(new
DefaultCellEditor(jcb_Defect));

// Set up the notes column cell renderer
jtbl_Positions.getColumnModel().getColumn(10).setCellRenderer(new
Note_Cell_Renderer());

// Don't allow multiple row selections

jtbl_Positions.getSelectionModel().setSelectionMode(ListSelectionModel.SINGL
E_SELECTION );

jtbl_Positions.getTableHeader().setReorderingAllowed(false);
jtbl_Positions.getTableHeader().setResizingAllowed(false);

Winder_Table_Model.Set_Column_Widths(jtbl_Positions);
}
 
C

Christophe Vanfleteren

KLD said:
Within my table model , two of the columns contain a JComboBox dropdown
of
choices. I want to make one of the JComboBoxes editable, jcb_Status (so
you
can select from the dropdown, or type text in the field). I can only seem
to get the first row in the table model to be editable, and then it does
not put the drop down list on the subsequent items in the combobox.

Winder_Table_Model _Winder_Table_Model = null;

public void Display_Pattern_Table()
{

_Winder_Table_Model = new Winder_Table_Model();
}

Not really an answer to your problem, but I do have a suggestion:

please use a better naming scheme for your code. Nobody writes code that
looks like that in Java. As such, it is both a pain and harder to read your
code, as it defies the naming conventions.
All those underscores you use made me want to cry :)

You can find the conventions here:
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

Considering following the in the future, it makes it easier for everyone
involved.
 
K

KLD

Christophe Vanfleteren said:
Not really an answer to your problem, but I do have a suggestion:

please use a better naming scheme for your code. Nobody writes code that
looks like that in Java. As such, it is both a pain and harder to read your
code, as it defies the naming conventions.
All those underscores you use made me want to cry :)

You can find the conventions here:
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

Considering following the in the future, it makes it easier for everyone
involved.

Please excuse my "ugly" naming conventions. I am a novice at this and am
just trying to enhance someone elses existing code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top