ERLEDIGT
NEIN
NEIN
ANTWORTEN
0
0
ZUGRIFFE
657
657
EMPFEHLEN
-
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.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(); } }
Trotzdem wird das richtige Element in der ComboBox nicht angezeigt, jedoch sobald man die ComboBox öffnet.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; } } } } } }
Irgend ne Idee?
Danke im Voraus
Gruß Jan
Ähnliche Themen
-
jTable mit jComboBox- Zellen plötzlich nicht mehr edittierbar...
Von Myar im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 0Letzter Beitrag: 03.09.08, 11:33 -
Elemente unsichtbar machen sofort aktualisieren...
Von Polli im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 7Letzter Beitrag: 16.05.08, 13:08 -
JComboBox und JMenu wollen Elemente nicht löschen...
Von TheMagican im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 3Letzter Beitrag: 23.07.07, 07:02 -
JTable CellEditor editingCanceled
Von nils_eckert im Forum JavaAntworten: 0Letzter Beitrag: 30.01.05, 20:08 -
JComboBox in JTable
Von himbeer im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 3Letzter Beitrag: 12.01.05, 16:54





Zitieren
Login




