Resizing JPanel within JScrollPane

Discussion in 'Java' started by McMatt, Feb 22, 2007.

  1. McMatt

    McMatt Guest

    Hello,

    how can the size of a JPanel automatically be calculated?

    The panel which is scrollable in the scrollpane has always the height
    which I set with setPreferredSize(Dimension). If the components on
    that panel need less place it should be smaller so that the scroll
    bars can disappear if not necessary. And if the components on that
    panel need more space it should be larger so that one can see all of
    the stuff when scrolling down.

    I hope the description is exact enough.

    Thanks for any help in advance.

    Matthias
     
    McMatt, Feb 22, 2007
    #1
    1. Advertising

  2. On Feb 23, 5:37 am, "McMatt" <> wrote:
    ...
    > how can the size of a JPanel automatically be calculated?


    Try..
    panel.validate();
    // then do nothing with preferred size..

    ...if that fails to do what's needed, I
    suggest you prepare an SSCCE of the code.
    <http://www.physci.org/codes/sscce>

    Andrew T.
     
    Andrew Thompson, Feb 22, 2007
    #2
    1. Advertising

  3. McMatt

    McMatt Guest

    Hello,

    thanks for the quick reply. During the preparation of a SSCCE it
    turned out that more elements are involved in it than expected.

    The main reason was a layout in on of the components.

    But I needed still a validate() call - namely scrollPane.validate().

    Thanks for your help,
    Kind regards,

    Matthias

    On 22 Feb., 19:49, "Andrew Thompson" <> wrote:
    > On Feb 23, 5:37 am, "McMatt" <> wrote:
    > ..
    >
    > > how can the size of a JPanel automatically be calculated?

    >
    > Try..
    > panel.validate();
    > // then do nothing with preferred size..
    >
    > ..if that fails to do what's needed, I
    > suggest you prepare an SSCCE of the code.
    > <http://www.physci.org/codes/sscce>
    >
    > Andrew T.
     
    McMatt, Feb 23, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    5
    Views:
    5,032
  2. ludaekipa
    Replies:
    2
    Views:
    2,181
    ludaekipa
    May 4, 2004
  3. Andreas Beresko

    Add a JPanel to a JPanel...

    Andreas Beresko, Jul 14, 2004, in forum: Java
    Replies:
    6
    Views:
    27,026
  4. Raphael Jolivet

    [JPanel] Drop Down JPanel

    Raphael Jolivet, Jul 18, 2008, in forum: Java
    Replies:
    1
    Views:
    1,542
    John B. Matthews
    Jul 18, 2008
  5. t1m1976
    Replies:
    1
    Views:
    2,442
    t1m1976
    Nov 7, 2010
Loading...

Share This Page