I have JScrollPanewith JTable. In JTablemy original 3 line. Later strings are added.
By default, JTablewith my 3 lines, it’s ugly because it JScrollPanecalls getPreferredScrollableViewportSizefrom the client ( JTable), and the return value is always the same. This is why my JTable/ JScrollPanewith 3 lines has this free space, JScrollpane andJTable don't have the same size.
My solution is to subclass JTable, override getPreferredScrollableViewportSizeand return to this function getPreferredSize();. Now all JScrollPanehas exactly the size of 3 lines of `JTable!
When a line is added, I have a command ((JComponent) scrollPane.getParent()).revalidate();
Scrollpauna grows with the table.
Everything works perfectly!
But now I want to set a specific layout for the scrollpane (panel) container:
myjpanel.setLayout (new BoxLayout(contentPane, BoxLayout.Y_AXIS));
When I add this command, my whole solution no longer works. Scrolling does not have the size of a table of 3 rows, this is free space again.
Why is this?
Does anyone have a solution?
CONTINUED
Thank you for pointing me in the right direction. My solution is this:
scrollPane = new JScrollPane (table) {
public Dimension getMaximumSize () {
double height = 0;
double width = super.getMaximumSize().getWidth();
height += columnHeader.getViewSize().getHeight();
height += viewport.getView().getPreferredSize().getHeight();
height += (getViewportBorderBounds().getHeight() * -1);
Dimension returnValue = new Dimension ((int) width, (int) height);
return returnValue;
}
};
Now it works in the beginning. But when the line is added to jtable, I call revalidate (); on jpanel (the parent container of the scroll bar) jscrollpanel is compressed in height to 1 line + header! Did anyone understand what to do in this situation.
CONTINUED
. viewportBorder. , , (Jtable), viewportBorder. getViewportBorderBounds().getHeight() -3, - - 48. , 48 .
, camickr , jscrollpane scrollpane. . jscrollpane 450 x 400 (http://www.javalobby.org/java/forums/t19559.html), jtable 3 . . - .
!
jscrollpane 0... sp.setBorder(createEmptyBorder());
, getViewportBorderBounds().getHeight()