Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't know if these are related but...</p> <pre><code>public void itemStateChanged(ItemEvent e) { int index = comboBox.getSelectedIndex(); System.out.println("index = " + index + "; " + (index + 1998)); model.setMonth(comboBox.getSelectedIndex() + 1998, list.getSelectedIndex()); table.repaint(); } </code></pre> <p>Doesn't produce results which match those that are listed within the combo box. For example, if you select the first value, it will equal <code>1998</code>, not <code>2008</code></p> <p>So, if I select <code>2013</code> from the combo box, I'm actually getting <code>2003</code>.</p> <p>When I changed it to </p> <pre><code>public void itemStateChanged(ItemEvent e) { int index = comboBox.getSelectedIndex(); System.out.println("index = " + index + "; " + (index + 2008)); model.setMonth(comboBox.getSelectedIndex() + 2008, list.getSelectedIndex()); table.repaint(); } </code></pre> <p>It gave me better results.</p> <p>I also changed</p> <pre><code>java.util.GregorianCalendar cal = new java.util.GregorianCalendar(); </code></pre> <p>to</p> <pre><code>java.util.Calendar cal = java.util.Calendar.getInstance(); </code></pre> <p>You should avoid making assumptions about the users calendar system if possible...</p> <p>I'd also avoid <code>null</code> layouts as well ;)</p> <p>You should also avoid calling <code>table.repaint</code> when you change the table model, instead try using <code>fireTableDataChanged</code> from within the <code>setMonth</code> method</p> <p>I would, personally, add the listeners to the combobox and <code>JList</code> before setting there selected indexes, this will allow the listeners to update the model for you...</p> <p>You'll also need to fix you <code>ListHandler</code> so that it uses <code>2008</code> instead <code>1998</code></p>
 

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