JScrollPane

Discussion in 'Java' started by Thorsten Kiefer, Mar 20, 2008.

  1. Hi,
    I need scroll pane which does not resize its child.
    I.e. the child must always keep its preferred size.
    If the scroll pane it bigger than the child, the child should
    be aligned to the scroll pane's center.

    Is something like that available ?

    Best wishes
    Thorsten
    Thorsten Kiefer, Mar 20, 2008
    #1
    1. Advertising

  2. Thorsten Kiefer

    Guest

    On Mar 20, 7:06 am, Thorsten Kiefer <> wrote:
    > Hi,
    > I need scroll pane which does not resize its child.
    > I.e. the child must always keep its preferred size.
    > If the scroll pane it bigger than the child, the child should
    > be aligned to the scroll pane's center.
    >
    > Is something like that available ?
    >
    > Best wishes
    > Thorsten


    Just add additional container inside JScrollPane:

    public class GUI {
    public static void main(String[] args) {
    JFrame frame=new JFrame();
    frame.setSize(500, 400);
    JButton button=new JButton("Click me");
    button.setPreferredSize(new Dimension(200, 40));
    JPanel panel=new JPanel();
    panel.add(button);
    JScrollPane scrollableArea = new JScrollPane(panel);
    frame.add(scrollableArea);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    }
    }

    Alex.
    http://www.myjavaserver.com/~alexfromohio/
    , Mar 20, 2008
    #2
    1. Advertising

  3. wrote:

    > On Mar 20, 7:06 am, Thorsten Kiefer <> wrote:
    >> Hi,
    >> I need scroll pane which does not resize its child.
    >> I.e. the child must always keep its preferred size.
    >> If the scroll pane it bigger than the child, the child should
    >> be aligned to the scroll pane's center.
    >>
    >> Is something like that available ?
    >>
    >> Best wishes
    >> Thorsten

    >
    > Just add additional container inside JScrollPane:
    >
    > public class GUI {
    > public static void main(String[] args) {
    > JFrame frame=new JFrame();
    > frame.setSize(500, 400);
    > JButton button=new JButton("Click me");
    > button.setPreferredSize(new Dimension(200, 40));
    > JPanel panel=new JPanel();
    > panel.add(button);
    > JScrollPane scrollableArea = new JScrollPane(panel);
    > frame.add(scrollableArea);
    > frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    > frame.setVisible(true);
    > }
    > }
    >
    > Alex.
    > http://www.myjavaserver.com/~alexfromohio/


    Cool, Thanks !!!
    Thorsten Kiefer, Mar 20, 2008
    #3
  4. Thorsten Kiefer

    Roedy Green Guest

    On Thu, 20 Mar 2008 12:06:27 +0100, Thorsten Kiefer
    <> wrote, quoted or indirectly quoted someone who
    said :

    >I need scroll pane which does not resize its child.
    >I.e. the child must always keep its preferred size.


    You could use setPreferredSize setMinimumSize setMaximumSize on the
    child and see if it honours your request.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Mar 20, 2008
    #4
    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. Richard Trahan

    JScrollPane scroll to top

    Richard Trahan, Jul 26, 2003, in forum: Java
    Replies:
    0
    Views:
    2,196
    Richard Trahan
    Jul 26, 2003
  2. Miguel De Anda
    Replies:
    0
    Views:
    597
    Miguel De Anda
    Aug 13, 2003
  3. soni29

    change jscrollpane bar?

    soni29, Aug 21, 2003, in forum: Java
    Replies:
    0
    Views:
    574
    soni29
    Aug 21, 2003
  4. Tobi Krausl
    Replies:
    0
    Views:
    1,802
    Tobi Krausl
    Nov 12, 2003
  5. Mike
    Replies:
    5
    Views:
    5,004
Loading...

Share This Page