• Post Reply Bookmark Topic Watch Topic
  • New Topic

Want to eliminate JTable Clipped Last Row

 
John Piekos
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I place my JTable in a scroll region, the scroll region is added to a panel. When I display this panel in an Applet (or a JDialog), depending on the size of the container, the last line of the table can be clipped, only partially displayed. I'd like to ensure that whenever the table is displayed, regardless as to the size of the outer container.
Now I have tried adding a container (and scroll region, and jtable) component listener to catch the ComponentResized notification. In there I call table.getScrollableBlockIncrement then call table.setPreferredScrollableViewportSize, but the size never seems to come out right. I am told that this is possible via MFC (but I am not an MFC programmer nor do I ever hope to be. :-) ). Anyone have any thoughts?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you determining the size that you send to table.setPreferredScrollableViewportSize()... to show all the rows the height should be :

height of header + ( height of row * number of rows )

and the width should be (if all columns are the same size):

( width of column * number of columns )

or (if your column size is variable):

( width of column 1 + width of column 2 + ... + width of column n )
 
John Piekos
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nate,
I am calling JTable.getScrollableBlockIncrement
to get the size of the scroll region. The JavaDoc API for this method says: "Returns visibleRect.height or visibleRect.width, depending on this table's orientation. Note that as of Swing 1.1.1 (Java 2 v 1.2.2) the value returned will ensure that the viewport is cleanly aligned on a row boundary."
Alignment on a row boundary is what I am hoping for. Anyone ever successfully use this method to do what I want to do?
Thanks,
John
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!