I have sort of an odd thing I'm doing. I have a JTable with several columns. Some of those columns are JComboBoxes. In particular, column indexes 9 and 10 are JComboBoxes. The catch is that the list in the JComboBox for column index 10 depends on the selected item in the JComboBox of column index 9. There are 5 different options in column index 9.
Now, I think I may have figured out the vast majority of this, but the problem I am having is setting the DefaultCelEditor for column index 10. When I create a new DefaultCellEditor and send it a JComboBox, I do not know which JComboBox content I need to send it (since it depends on each row and when the data in column index 9 changes).
This is my current code for column indexes 9 and 10 (the commented section at the bottom is the issue I am having):
table.getColumnModel().getColumn(9).setCellRenderer(new TableCellRenderer() { public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected,boolean isFocused, int row, int col) { JComboBox rendererComponent = new JComboBox(new Vector<String>(evPh)); rendererComponent.setSelectedItem(value.toString()); return rendererComponent; } }); DefaultCellEditor cellEditor2 = new DefaultCellEditor(new JComboBox(new Vector<String>(evPh))); cellEditor.setClickCountToStart(1); table.getColumnModel().getColumn(9).setCellEditor(cellEditor2); table.getColumnModel().getColumn(10).setCellRenderer(new TableCellRenderer() { public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected,boolean isFocused, int row, int col) { Vector<String> list0 = new Vector<String>(); for(int i=0;i<txoPhase.length;i++) list0.add(txoPhase[i]); Vector<String> list1 = new Vector<String>(); for(int i=0;i<txiPhase.length;i++) list1.add(txiPhase[i]); Vector<String> list2 = new Vector<String>(); for(int i=0;i<dvoPhase.length;i++) list2.add(dvoPhase[i]); Vector<String> list3 = new Vector<String>(); for(int i=0;i<dvfPhase.length;i++) list3.add(dvfPhase[i]); Vector<String> list4 = new Vector<String>(); for(int i=0;i<naPhase.length;i++) list4.add(naPhase[i]); JComboBox rendererComponent; String prevValue = table.getValueAt(row,9).toString(); if(prevValue.equalsIgnoreCase("TXO")) rendererComponent = new JComboBox(new Vector<String>(list0)); else if(prevValue.equalsIgnoreCase("TXI")) rendererComponent = new JComboBox(new Vector<String>(list1)); else if(prevValue.equalsIgnoreCase("DVO")) rendererComponent = new JComboBox(new Vector<String>(list2)); else if(prevValue.equalsIgnoreCase("DVF")) rendererComponent = new JComboBox(new Vector<String>(list3)); else rendererComponent = new JComboBox(new Vector<String>(list4)); rendererComponent.setSelectedItem(value.toString()); return rendererComponent; } }); //DefaultCellEditor cellEditor5 = new DefaultCellEditor(new JComboBox()); //cellEditor.setClickCountToStart(1); //table.getColumnModel().getColumn(10).setCellEditor(cellEditor5);
Is anyone able to point me in the correct direction?