How to create a JComboBox in a JTable column with JFormDesigner

In a heavy day of JFormDesigner use, I just learned how to create a JComboBox in a column in a JTable, using only JFormDesigner.

First, create your JTable in JFormDesigner. I'll skip the details here, hoping that process is easy enough. Then, click the ellipsis button for the model property in the Properties list. This brings up the JTable model editor.

In the model editor dialog, click any cell in the column where you want to create the JComboBox. Then, in the bottom/middle of the model editor dialog, click the "Edit..." button just to the right of the "Values" field. This brings up a dialog named "Column Cell Editor Values".

On this dialog, just key in the values you want to display in your combo box for this column in the field labeled "ComboBox model items". Add one item per line, then click "OK". Then you'll see the values you've entered are now shown in the "Values" field on the model form. Click "OK" on that form and you're done. You can now preview your form and click in any cell of that column, and you'll see your new combox box.

JComboBox JTable source code

After you've done this, you'll end up generating the following JComboBox/JTable code. The JTable column with the JComboBox is column number 12.

{
TableColumnModel cm = myTable.getColumnModel();
  cm.getColumn(0).setResizable(false);
  cm.getColumn(0).setPreferredWidth(45);
  cm.getColumn(1).setResizable(false);
  cm.getColumn(1).setPreferredWidth(45);
  cm.getColumn(2).setResizable(false);
  cm.getColumn(2).setPreferredWidth(45);
  cm.getColumn(6).setPreferredWidth(55);
  cm.getColumn(7).setPreferredWidth(55);
  cm.getColumn(12).setCellEditor(new DefaultCellEditor(
    new JComboBox(new DefaultComboBoxModel(new String[] {
      "Yes",
      "No",
      "Maybe"
    }))));
}

I haven't created any JComboBox/JTable code before, so I thought I'd share this example here.