JScrollPane

T

Thorsten Kiefer

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
 
A

Alex.From.Ohio.Java

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/
 
T

Thorsten Kiefer

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 !!!
 
R

Roedy Green

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top