?
Solved

Adding ScrollBars to JPanel

Posted on 2003-03-31
16
Medium Priority
?
510 Views
Last Modified: 2008-03-10
Hi ,

  I have JFrame, over which i have a JInternalFrame. On this JInternalFrame i am displaying an Image using JPanel, ie JPanel which contains the image is placed on JInternalFrame.

Code is like this.

class myclass extends JPanel{
...
----
// constructor
myclass()
{
-- --
--
JScrollPane scroll = new JScrollPane(this);

}

}
i have set the color of scrollpane to white(for testing the presence)

When the image is displayed the scrollpane appears as a bar next to image,
when the image is zoomed, this bar disappears and the image is zoomed, but no scrollbars appear.

can i get help for this,

regards
0
Comment
Question by:alpjose
[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
  • 5
  • 5
  • 4
  • +1
16 Comments
 

Expert Comment

by:weelink
ID: 8244997
How did you filled the scrollpane with the image?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8245133
JScrollPane scroll = new JScrollPane ( this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED ) ;

Mayank.
0
 

Expert Comment

by:weelink
ID: 8245260
When I want a image with scrollbars I do the following:

ImageIcon image = new ImageIcon("image.gif");
JLabel lblImage = new JLabel(image);

JScrollPane scrollPane = new JScrollPane(lblImage);


Does this help?
0
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.

 

Author Comment

by:alpjose
ID: 8258997
Hi ,

  I have added image to JPanel. then added this JPanel to JScrollPane.
This object of scrollpane is called in another class which is JInternalFrame.

When the image is zoomed the scrollbars appear and if the mouse is just moved a bit on the image immediately the scrollbars disappear.

this is the problem.

i have used this.

JScrollPane scroll = new JScrollPane ( this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED ) ;

thanks and regards


0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8259074
Try:

JScrollPane scroll = new JScrollPane ( this, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS ) ;

Mayank.
0
 

Author Comment

by:alpjose
ID: 8259249
mayank, i have tried this also, same thing happens, when the image is zoomed, scrollbars appear and when the mouse is just moved on the image , i think when it get repainted it immediately disappears,
what can be be done for this
0
 

Expert Comment

by:weelink
ID: 8259308
Did you implement a MouseListener somewhere?
0
 

Author Comment

by:alpjose
ID: 8259406
yes i have implemented MouseListener,
0
 

Expert Comment

by:weelink
ID: 8260145
Does this MouseListener has anything to do with the scrollpane? And if so, could you post the code?
0
 

Author Comment

by:alpjose
ID: 8260478
Now the Scrollbars doesn't disappear, the scrollbars(both horizontal and vertical) are visible.

I have set the preferredSize(800,800);, so it is appearing, but when the scrollbars are scrolled, without zooming, repainting becomes very slow it becomes alright when i minimize and maximize the window, is there a way out of this.

once zoomed and scrolled, it works quiet OK,not perfectly.

0
 
LVL 30

Accepted Solution

by:
Mayank S earned 160 total points
ID: 8260534
>> Now the Scrollbars doesn't disappear,

Yeah! Because we used: ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS

Mayank.
0
 

Author Comment

by:alpjose
ID: 8268677
Hi,
  Thank you , it works properly.
  The Component's setPreferredSize() method has to be used for the JScrollpane to work properly.

And for repaint problem, in the paint method paintComponent() method has to be used.


it works fine.

Pls close this question

Thanks and Regards


0
 

Expert Comment

by:CleanupPing
ID: 9446610
alpjose:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9451763
Recommendation: Accept mayankeagle's comment as answer.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Introduction to Processes
Starting up a Project
Suggested Courses

770 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