7 Replies - 2406 Views - Last Post: 02 October 2010 - 11:07 PM Rate Topic: -----

#1 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

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 :(

Is This A Good Question/Topic? 0
  • +

Replies To: Scrolling a JPanel Image

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2695
  • View blog
  • Posts: 10,556
  • Joined: 15-July 08

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?
Was This Post Helpful? 0
  • +
  • -

#3 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

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...

Posted Image
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2695
  • View blog
  • Posts: 10,556
  • Joined: 15-July 08

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.
Was This Post Helpful? 1
  • +
  • -

#5 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Scrolling a JPanel Image

Posted 02 October 2010 - 10:31 PM

Alrighty got it working, thanks a lot :)
Was This Post Helpful? 0
  • +
  • -

#6 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2695
  • View blog
  • Posts: 10,556
  • Joined: 15-July 08

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?
Was This Post Helpful? 0
  • +
  • -

#7 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

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.
Was This Post Helpful? 0
  • +
  • -

#8 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2695
  • View blog
  • Posts: 10,556
  • Joined: 15-July 08

Re: Scrolling a JPanel Image

Posted 02 October 2010 - 11:07 PM

Sweet. Glad to know that it worked.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1