title: Limit rows shown in JTable + Next/Previous button
body: <p>I'm trying to create a JTable that's only showing one row at the time. When you press Next/Previous, the table will display either the next or the previous row, depending on the button pressed. If there is no Next/Previous, the JTable shall display the first/last element.</p>
  
  <p>Code for only showing one row at a time:</p>
  
  <pre><code>tableModel = new DefaultTableModel(data, columnNames);
  tableModel.setRowCount(0); //If I remove this, the things I add ends up att the 2nd line.
  tableModel.addTableModelListener(resultTable);
  resultTable = new JTable(tableModel);
  scroll = new JScrollPane(resultTable, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  
  final int rows = 1;
  Dimension d = resultTable.getPreferredSize();
  resultTable.setPreferredSize(new Dimension(d.width,resultTable.getRowHeight()*rows));
  </code></pre>
  
  <p>Code for Next-button (Not working, what do to? Shows the same element as before):</p>
  
  <pre><code>int height = resultTable.getRowHeight()*(rows-1);
  JScrollBar bar = scroll.getVerticalScrollBar();
  bar.setValue( bar.getValue()+height);
  </code></pre>
  
  <p>Code for Previous-button (Not working, same as above, nothing happens/changes.)</p>
  
  <pre><code>int height = resultTable.getRowHeight()*(rows-1);
  JScrollBar bar = scroll.getVerticalScrollBar();
  bar.setValue(bar.getValue()-height);
  </code></pre>
  
  <p>What do to? Some help would be greatly appreciated. Been trying to solve this forever.</p>
  
  <p>Edit: Trying to follow the code from here: <a href="https://stackoverflow.com/questions/6175139/jtable-row-limitation">JTable row limitation</a> but can't get it to work.. Though I only want to show 1 row, not 10.</p>