JPanel in Scrollpane

From: Gemmel (gunmuc_at_gmx.de)
Date: 10/28/04


Date: 28 Oct 2004 12:31:43 -0700

Hi!

i have a panel in a scrollpane. the panel has a preferred size of 300
x 300 pixel. the scrollpane fits in the main frame, and shows
scrollbars when needed.

i overwrote the paintComponent method, to draw some rectangles.
problem here: the cliparea is not 300 x 300 pixel, but the inside area
of the scrollpane. because of that im not able to draw exactly into
the panel.

I want to reach the following result:

the panel has a constant size of 300 x 300. the scrollpane is
flexible. the panel should always be in the center of the scrollpane,
whenever the scrollpane is larger than 300 x 300 pixel. the unused
space in the scrollpane should be darkgray.
if the scrollpane is resized to a smaller size than 300x300,
scrollbars should appear.

How can i get this effect?

Thanks
  Gunter



Relevant Pages

  • Re: JPanel in Scrollpane
    ... > i have a panel in a scrollpane. ... The layout strategy of the layoutmanager of the viewport ...
    (comp.lang.java.gui)
  • Re: JPanel in Scrollpane
    ... I saw your reply to the posting about the 'JPanel in ScrollPane' on ... the panel should always be in the center of the scrollpane, ... > a) Set a different LayoutManager for the Viewport. ...
    (comp.lang.java.gui)
  • Re: How do I anchor JPanel location?
    ... In other words the scrollpane would contain the panel that can collapse. ... That way the scrollpane still takes up the space, and the other panels wont take it. ... JPanel should have a scrollpane inside of it, or the panel surrounding ...
    (comp.lang.java.programmer)
  • Re: Custom Component wont fit in a JScrollPane
    ... panel after insertion of those labels and checkboxes. ... Maybe the scrollpane ...
    (comp.lang.java.gui)
  • Re: scrollbars not becoming active
    ... If enough buttons/textfields get created they end up becoming miniscule on the screen, about the size of 50x50 pixels and it's due to the scroll bars not working. ... many attributes then my jdialog looks fine (unless you resize the window ... I figured out that the size of the scrollpane hadn't been set so it was effectively 0x0 in size. ... I found that out by accidentally modifying the size of the scrollpane of a panel that contained another scrollpane on another tab and it messed up the scrollpane and I narrowed down that change to setting a preferredSize so I went from there fixing the original scrollpane problem. ...
    (comp.lang.java.gui)