• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 515
  • Last Modified:

Adding ScrollBars to JPanel

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
alpjose
Asked:
alpjose
  • 5
  • 5
  • 4
  • +1
1 Solution
 
weelinkCommented:
How did you filled the scrollpane with the image?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
JScrollPane scroll = new JScrollPane ( this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED ) ;

Mayank.
0
 
weelinkCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
weelinkCommented:
0
 
alpjoseAuthor Commented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
Try:

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

Mayank.
0
 
alpjoseAuthor Commented:
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
 
weelinkCommented:
Did you implement a MouseListener somewhere?
0
 
alpjoseAuthor Commented:
yes i have implemented MouseListener,
0
 
weelinkCommented:
Does this MouseListener has anything to do with the scrollpane? And if so, could you post the code?
0
 
alpjoseAuthor Commented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
>> Now the Scrollbars doesn't disappear,

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

Mayank.
0
 
alpjoseAuthor Commented:
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
 
CleanupPingCommented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
Recommendation: Accept mayankeagle's comment as answer.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 5
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now