So far I have tried to set the size of the scrollpane, jpanel, even placing a component inside the jpanel as invisible and all attempts have been unsuccessful
Scrolling a JPanel Image
Page 1 of 17 Replies - 2406 Views - Last Post: 02 October 2010 - 11:07 PM
#1
Scrolling a JPanel Image
Posted 02 October 2010 - 10:01 PM
Well, I'm stuck trying to scroll an image in a JPanel using a scrollpane. Since there is nothing in the JPanel except for the image, the size of the JPanel is never big enough for the scrollpane to become active...any ideas on how to fix this problem would be greatly appreciated.
So far I have tried to set the size of the scrollpane, jpanel, even placing a component inside the jpanel as invisible and all attempts have been unsuccessful
So far I have tried to set the size of the scrollpane, jpanel, even placing a component inside the jpanel as invisible and all attempts have been unsuccessful
Replies To: Scrolling a JPanel Image
#2
Re: Scrolling a JPanel Image
Posted 02 October 2010 - 10:09 PM
Alright, what layout manager are you using? How are you displaying the image? And what is the preferredSize() of the component?
#3
Re: Scrolling a JPanel Image
Posted 02 October 2010 - 10:16 PM
Well actually, there are two JPanels, one in the left side and one in the right side of a JSplitPane. Overriding the paint component to draw the image and no set preferred size at the moment for any component...the JSplitPane divides the two portions of the program exactly in half though and I'd like a JScrollPane in each portion since the images are to be side by side...
#4
Re: Scrolling a JPanel Image
Posted 02 October 2010 - 10:19 PM
Alright, it's as I suspected. Since you are painting it on the screen, the component technically has no size...You should set the preferred size of the component in the paint() or paintComponent() method based on the size of the image that you are drawing OR use an ImageIcon. The latter method is preferred.
#5
Re: Scrolling a JPanel Image
Posted 02 October 2010 - 10:31 PM
Alrighty got it working, thanks a lot
#6
Re: Scrolling a JPanel Image
Posted 02 October 2010 - 10:57 PM
You're very welcome. Glad I could help. Out of curiosity, which method did you use?
#7
Re: Scrolling a JPanel Image
Posted 02 October 2010 - 11:01 PM
Ended up using the former method. Tried the ImageIcon first but couldn't add an imageicon to a JPanel and didn't feel like reworking a JPanel class into an ImageIcon class.
#8
Re: Scrolling a JPanel Image
Posted 02 October 2010 - 11:07 PM
Sweet. Glad to know that it worked.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|