I am doing a DatabaseManager Proyect where I display all the data of a db table in a JTable. Now I want to insert a feature so that the foreign keys of a table are displayed as a ComboBox with the values of the foreign table. So I was wondering which is the most optimal way to do it, I know that the Column which 开发者_StackOverflow社区represent the foreing key is going to be filled with comboBoxes with the exact same values, but every each of them will have a specific default starting value. Here is the code that I have right now to just fill the data without comboBoxes:
private Collection<Map<String, String>> allData;
Object[] rowToAdd = new Object[manager.get((String) DatabaseJList.getInstance().getSelectedObject()).getDataManager().getColumnNumber()];
for (Map<String, String> rowz: allData)
{
rowx = rowz.values();
int i = 0;
for (String str : rowx)
{
rowToAdd[i] = str;
i++;
}
tableModel.addRow(rowToAdd);
}
So since rowToAdd is an array of Objects, can I just create a comboBox and put it inside?Any suggestions how to do this?
Thanks a lot everyone.
You don't add the data to the model. You just specify that a combo box is to be used as the editor for the specific. See the section from the Swing tutorial on Using a Combo Box as an Editor for a working example.
精彩评论