levg
asked on
JScrollPane - how to enable scrolling?
Hi there!
I'd like to add JLabel to JScrollPane.
Say,
jScrollPane.setBounds(0,0, 100,100);
jLabel.setBounds(0,0,150,1 50);
jScrollPane.add(jLabel,nul l);
How should I enable scrolling EXACTLY (150-100=) 50 pixels to each side?
And in common - I need exact scrolling enabled only when I get:
jLabel.getHeight() > jScrollPane.getHeight() or/and jLabel.getWidth() > jScrollPane.getWidth()
Thank you in advance.
I'd like to add JLabel to JScrollPane.
Say,
jScrollPane.setBounds(0,0,
jLabel.setBounds(0,0,150,1
jScrollPane.add(jLabel,nul
How should I enable scrolling EXACTLY (150-100=) 50 pixels to each side?
And in common - I need exact scrolling enabled only when I get:
jLabel.getHeight() > jScrollPane.getHeight() or/and jLabel.getWidth() > jScrollPane.getWidth()
Thank you in advance.
JScrollPane uses the preferredSize of the child component to determine how to scroll.
If you use absolute positioning of the child you need to set the preferred size explicitly:
label.setPreferredSize(new Dimension(150,150));
also you would want to set the scroll policy for the scrollPane.
use these constants in the JScrollPane constructor:
JScrollPane.VERTICAL_SCROL LBAR_AS_NE EDED
JScrollPane.HORIZONTAL_SCR OLLBAR_AS_ NEEDED
If you use absolute positioning of the child you need to set the preferred size explicitly:
label.setPreferredSize(new
also you would want to set the scroll policy for the scrollPane.
use these constants in the JScrollPane constructor:
JScrollPane.VERTICAL_SCROL
JScrollPane.HORIZONTAL_SCR
ASKER
Well it works. Thank you. Come and grab the points.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER