JScrollPane, JTable and horizontal scroll

I was coding a graphical interface using Java, and what I wanted was to insert a JTable object inside a JScrollPane. The table was bigger than the JScrollPane, but I didnt know why, only the vertical scroll bar was shown. I spent hours reading Swing tutorials, checking my code… everything seemed to be ok, so.. why it wasnt working?
Finally, I found the answer: there is a bug in Java when you are using JScrollPane and JTable. And the solution was to create a new class extending JTable, in order to override JTable.getScrollableTracksViewportWidth() method with this one:

public boolean getScrollableTracksViewportWidth() {

if (autoResizeMode != AUTO_RESIZE_OFF) {

if (getParent() instanceof JViewport) {

return (((JViewport)getParent()).getWidth() > getPreferredSize().width);

}

}

return false;

}

Source: DaniWeb Forum

Bookmark and Share

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.