alpjose
asked on
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
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
How did you filled the scrollpane with the image?
JScrollPane scroll = new JScrollPane ( this, ScrollPaneConstants.VERTIC AL_SCROLLB AR_AS_NEED ED, ScrollPaneConstants.HORIZO NTAL_SCROL LBAR_AS_NE EDED ) ;
Mayank.
Mayank.
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?
ImageIcon image = new ImageIcon("image.gif");
JLabel lblImage = new JLabel(image);
JScrollPane scrollPane = new JScrollPane(lblImage);
Does this help?
You could take a look here:
http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html
http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html
ASKER
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.VERTIC AL_SCROLLB AR_AS_NEED ED, ScrollPaneConstants.HORIZO NTAL_SCROL LBAR_AS_NE EDED ) ;
thanks and regards
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.VERTIC
thanks and regards
Try:
JScrollPane scroll = new JScrollPane ( this, ScrollPaneConstants.VERTIC AL_SCROLLB AR_ALWAYS, ScrollPaneConstants.HORIZO NTAL_SCROL LBAR_ALWAY S ) ;
Mayank.
JScrollPane scroll = new JScrollPane ( this, ScrollPaneConstants.VERTIC
Mayank.
ASKER
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
what can be be done for this
Did you implement a MouseListener somewhere?
ASKER
yes i have implemented MouseListener,
Does this MouseListener has anything to do with the scrollpane? And if so, could you post the code?
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
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.
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.
Recommendation: Accept mayankeagle's comment as answer.