Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal Scrolling + JTable + Java

I checked the questions on stackoverflow concerning getting horizontal scrolling on a JTable to work. Setting AUTO_RESIZE_OFF does get me the horizontal scroll bar but at the same time the table does not utilize the full width of the scroll pane.

I did some reading and it turns out this has been a running bug since 1998 (Will Oracle fix this?)

I saw some suggestions about over riding methods etc but none worked for me. So does anyone have an answer? It would be much appreciated. Basically I need the table to auto resize but enable the horizontal scroll bar before any of the column names get compressed.

Thanks.

like image 427
Mark Avatar asked Sep 13 '11 09:09

Mark


1 Answers

after ranting against the other answers - JXTable (in the SwingX project) has an additional column layout property which

  • fills the horizontal viewport (that is increases the column width) if their combined pref is less than the current width, respecting the autoResizeMode
  • keeps the column sizes at their pref and shows the horizontal scrollbar if their combined pref is greater than the current width

There's a bit of internal tweaking needed, so (biased me) would suggest to use the JXTable. Or have a look at its code and c&p - all allowed, all open source :-)

like image 62
kleopatra Avatar answered Oct 06 '22 06:10

kleopatra