Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JScrollPane - how to enable scrolling?

Posted on 1999-07-19
4
Medium Priority
?
255 Views
Last Modified: 2008-02-26
Hi there!
I'd like to add JLabel to JScrollPane.
Say,
jScrollPane.setBounds(0,0,100,100);
jLabel.setBounds(0,0,150,150);
jScrollPane.add(jLabel,null);
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.
0
Comment
Question by:levg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:levg
ID: 1246426
Edited text of question.
0
 
LVL 7

Expert Comment

by:conick
ID: 1246427
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_SCROLLBAR_AS_NEEDED
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED

0
 

Author Comment

by:levg
ID: 1246428
Well it works. Thank you. Come and grab the points.
0
 
LVL 7

Accepted Solution

by:
conick earned 200 total points
ID: 1246429
Great Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question