Note that there are some explanatory texts on larger screens.

plurals
  1. POScroll horizontally in JTable with Nimbus look and feel
    primarykey
    data
    text
    <p>I have a JTable that is wider than the JScrollPane it is contained in (essentially defined like this):</p> <pre><code>JTable table = new JTable(model); // I change some things like disallowing reordering, resizing, // disable column selection, etc. // I set the default renderer to a DefaultTableCellRenderer // getTableCellRendererComponent, and then changes the color // of the cell text depending on the cell value JPanel panel = new JPanel(new BorderLayout(0, 5)); panel.add(new JScrollPane(table), BorderLayout.CENTER); // add other stuff to the panel this.add(panel, BorderLayout.CENTER); </code></pre> <p>Before I changed the look and feel from the default to Nimbus, I was able to scroll left and right in the JTable. (I like the Mac LaF, but it isn't supported on Windows, and the Windows LaF is ugly in my opinion),</p> <p>I took the following code straight from the Java Tutorials:</p> <pre><code>try { for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (Exception e) { // If Nimbus is not available, you can set the GUI to another look // and feel. } </code></pre> <p>I recompiled and ran the code without changing any of the table definition stuff above, and I couldn't scroll horizontally in the JTable anymore.</p> <p>I can't seem to find anything on what would cause this. Is this the normal behavior for Nimbus, or can I change it? If so, how? or should I just try a different look and feel?</p> <p><strong>EDIT:</strong></p> <p>I discovered two things:</p> <ol> <li><p>I made a new class extending JTable to test this. I copied the code for <code>getScrollableUnitIncrement</code> from the JTable source, and added print statements. The orientation that is passed seems to always be <code>SwingConstants.VERTICAL</code>, while in the default Look and Feel (Mac Aqua or whatever), both horizontal and vertical scrolling works. I don't know why this is.</p></li> <li><p>Another part of the project also relies on horizontal scrolling. I tested it with both LaFs, and it worked fine in the default, but Nimbus would not allow me to scroll horizontally, either.</p></li> </ol> <p>Could this be a bug with Nimbus?</p> <p>Either way, I guess I'm going to use a different Look and Feel...</p> <p><strong>EDIT #2:</strong></p> <p>I should have mentioned this before. I <em>am</em> able to scroll horizontally with the scroll bar in the window, but not with my track pad or scroll wheel on my mouse.</p>
    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.
    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