Note that there are some explanatory texts on larger screens.

plurals
  1. POConditional JComboBox inside JTable - How to Automatically change values
    primarykey
    data
    text
    <p>I have a table filled with comboboxes, What I want to do is the folowing: If an element in a combobox is selected, then automatically change the selection on another combo (the reciprocal). I can't figureout a way to do it. Here I post an image describing what I want to do. <img src="https://i.stack.imgur.com/quU3W.png" alt="Matrix automatic JComboboxUpdate"></p> <p>The code of my table is the following:</p> <pre><code>public void createCriteriaMatrix(){ jTableCriteria = new JTable(); // COLUMNS String[] column = new String[problem.getCriteria()+1]; for(int i=0; i&lt;problem.getCriteria()+1; i++){ column [i] = " "+i; if(i==0){ column [i] = " "; } } // DATA CELLS String [][] data = new String[problem.getCriteria()][problem.getCriteria()+1]; for(int j=0; j&lt;problem.getCriteria()+1; j++){ for(int i=0; i&lt;problem.getCriteria(); i++){ data [i][j]=" "; if(j==0){ data [i][j] = " "+(i+1); } } } //SOME TABLE FORMAT DefaultTableModel model = new DefaultTableModel(data , column ){ @Override public boolean isCellEditable(int row, int column) { return column != 0; } }; //Calling to RenderCells() to format cell colors jTableCriteria.setDefaultRenderer (Object.class, new RenderCells()); jTableCriteria.setModel(model); jTableCriteria.getTableHeader().setReorderingAllowed(false); this.placeCombosTable(); } public void placeCombosTable(){ for(int i=0; i&lt;=problem.getCriteria(); i++){ for(int j=0; j&lt;=problem.getCriteria(); j++){ TableColumn weighting= jTableCriteria.getColumnModel().getColumn(i); JComboBox comboBox = new JComboBox(); comboBox.addItem("1"); comboBox.addItem("2"); comboBox.addItem("3"); comboBox.addItem("4"); comboBox.addItem("5"); comboBox.addItem("6"); comboBox.addItem("7"); comboBox.addItem("1/2"); comboBox.addItem("1/3"); comboBox.addItem("1/4"); comboBox.addItem("1/5"); comboBox.addItem("1/6"); comboBox.addItem("1/7"); if(i==j){ comboBox.setSelectedIndex(0); } weighting.setCellEditor(new DefaultCellEditor(comboBox)); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload