Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I solved it with an Array for the reciprocal pairwise comparison (to compare and then set the other combo with the correct value), a Listener for the combobox and a setValueAt() instead of a setSelectedItem(). The code is the following: </p> <pre><code> 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); } //SCALE final String scale[][] = { { "1", "2", "3", "4", "5", "6", "7" }, { "1", "1/2", "1/3","1/4","1/5","1/6","1/7" } }; //LISTENER comboBox.addActionListener( new ActionListener(){ @Override public void actionPerformed(ActionEvent e){ JComboBox combo = (JComboBox)e.getSource(); //LOOK FOR THE RECIPROCAL ON THE SCALE String item = (String)combo.getSelectedItem(); String itemReciprocal = ""; for (int i = 0; i &lt;= 0; i++) { for (int j = 0; j &lt; 7; j++) { if(item.equalsIgnoreCase(scale[i][j])){ itemReciprocal = scale[1][j]; } } } //WITH THE RECIPROCAL I PROCEEDE TO SET THE CORRESPONDING CELL int row = jTableCriteria.getSelectedRow()+1; int column = jTableCriteria.getSelectedColumn(); int reciprocalRow = column ; int reciprocalColumn = row ; jTableCriteria.getModel().setValueAt(itemReciprocal, reciprocalRow , reciprocalColumn ); } } ); weighting.setCellEditor(new DefaultCellEditor(comboBox)); } } } </code></pre>
 

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