Cell Editor Combo Box - Tablle aktualisieren
-
HAllo ich habe eine Jtable mit einem eigenen Cell Editor für ComboBox.
Wenn ich nun in der Combox einen Wert auswähle wird dieser Wert in der Tablle (Zelle) nicht dargestellt.Hier ist der Code vom Cell Editor :
public class TestRunTableComboBoxEditor extends DefaultCellEditor implements TableCellEditor { private JComboBox comboBox; /** * @param comboBox */ public TestRunTableComboBoxEditor(JComboBox comboBox) { super(comboBox); this.comboBox = comboBox; } @Override public Object getCellEditorValue() { return comboBox; } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { // select the value comboBox.setSelectedItem(value); return comboBox; } }
Hier wird der Zell Editor zu der Tabelle hinzugefügt.
testRunTable.setDefaultEditor(JComboBox.class, new TestRunTableComboBoxEditor(comboBox));
Und hier ist der Code für das Model :
public class TestRunTableModel implements TableModel { private String[] tableHeader = new String[] {"", "TestCaseID", "TestVariantID", "ErrorType", "Manual Comment", "Ticket"}; private Vector<TestVariantResult> testVariantResultList; /** * */ public TestRunTableModel() { this.testVariantResultList = new Vector<TestVariantResult>(); } /** * */ public TestRunTableModel(Vector<TestVariantResult> testVariantResultList) { this.testVariantResultList = testVariantResultList; } @Override public int getRowCount() { return testVariantResultList.size(); } @Override public int getColumnCount() { return tableHeader.length; } @Override public String getColumnName(int columnIndex) { return tableHeader[columnIndex]; } @Override public Class<?> getColumnClass(int columnIndex) { switch (columnIndex) { case 0: return Boolean.class; case 3: return JComboBox.class; case 4: case 5: return JTextField.class; default: return String.class; } } @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return true; } @Override public Object getValueAt(int rowIndex, int columnIndex) { TestVariantResult testVariantResultObj = testVariantResultList.get(rowIndex); if (columnIndex == 0) { return false; } // print the test case id if (columnIndex == 1) { return testVariantResultObj.getTestCaseDescription().getTestCaseID(); } // if the object is an test variant print the properties if (testVariantResultObj.isTestVariantResult() == true) { switch(columnIndex) { // print the test variant id case 2: return testVariantResultObj.getTestVariantID(); // print the ErrorType case 3: return testVariantResultObj.getTestVariantResultErrorType(); // print the Manual Comment case 4: return testVariantResultObj.getTestVariantResultManualComment(); } } return ""; } @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { // TODO Auto-generated method stub } @Override public void addTableModelListener(TableModelListener l) { // TODO Auto-generated method stub }
Vielen Dank für eure Hilfe.