Hi Leute,
habe in einem CellEditor eine ComboBox erstellt und diese in einer JTable genutzt.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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();
    }
}
Nun lade ich die Daten in die Tabelle und wähle den richtigen Eintrag in der ComboBox aus.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
                        }
                    }
                }
            }
        }
    }
Trotzdem wird das richtige Element in der ComboBox nicht angezeigt, jedoch sobald man die ComboBox öffnet.
Irgend ne Idee?

Danke im Voraus

Gruß Jan