Hi Leute,
habe in einem CellEditor eine ComboBox erstellt und diese in einer JTable genutzt.
Nun lade ich die Daten in die Tabelle und wähle den richtigen Eintrag in der ComboBox aus.
Trotzdem wird das richtige Element in der ComboBox nicht angezeigt, jedoch sobald man die ComboBox öffnet.
Irgend ne Idee?
Danke im Voraus
Gruß Jan
habe in einem CellEditor eine ComboBox erstellt und diese in einer JTable genutzt.
Java:
public class CellEditorComboBox extends DefaultCellEditor {
private static final long serialVersionUID = -3831989493413833105L;
private JComboBox comboBox;
public JComboBox getComboBox() {
return comboBox;
}
public CellEditorComboBox(Object[] items) {
super(new JComboBox(items));
this.comboBox = (JComboBox) this.getComponent();
}
}
Java:
private void setComboBoxElements() {
for (int i = 0; i < this.tableBerechtigung.getColumnCount(); i++) {
TableCellEditor cellEditor = this.tableBerechtigung
.getColumnModel().getColumn(i).getCellEditor();
if (cellEditor instanceof CellEditorComboBox) {
CellEditorComboBox comboBox = (CellEditorComboBox) cellEditor;
for (int j = 0; j < this.tableBerechtigung.getRowCount(); j++) {
Object obj = this.tableBerechtigung.getModel().getValueAt(
j, i);
String comparekey = null;
for (int q = 0; q < comboBox.getComboBox().getItemCount(); q++) {
Object item = comboBox.getComboBox().getItemAt(q);
if (item instanceof BaseDataBean) {
comparekey = ((BaseDataBean) item).getKey();
}
if (comparekey != null
&& comparekey.equals(obj.toString())) {
// comboBox.getComboBox().setSelectedIndex(q);
comboBox.getComboBox().getModel().setSelectedItem(
comboBox.getComboBox().getModel()
.getElementAt(q));
// this.tableBerechtigung.getModel().setValueAt(obj,
// j, i);
break;
}
}
}
}
}
}
Irgend ne Idee?
Danke im Voraus
Gruß Jan