• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting scrollbars to scroll

 
Scott Kimberly
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured out how to setup scroll bars so that they appear on the proper components.

I have a frame that the scrollpane is being added to that is 500x500.

My panel that is the component for the scrollpane is an image that is 640x640.

When i run my program, it makes the image in a 500x500 frame and generates the image at its 640x640. It adds in the scrollbars, but they dont do anything. What piece of this puzzle am i missing?

 
Darryl Burke
Bartender
Posts: 5154
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott Kimberly wrote:What piece of this puzzle am i missing?


The piece that would allow us to suggest a correction. To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
 
Scott Kimberly
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


drawP: gets images and then recompiles them to make a map. drawP extends JPanel.
 
Darryl Burke
Bartender
Posts: 5154
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you even click the link to the page that describes the SSCCE?? Or is it that you really don't want better help sooner?
 
Scott Kimberly
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Did you even click the link to the page that describes the SSCCE?? Or is it that you really don't want better help sooner?


How can you not answer this question based off of theories behind what im trying to do and how can you not do it off of the code i just provided? I promise you youll need ALL of my code to experience what im experiencing.



Load in your own image thats larger then 500x500 and see what happens. That code is as SSCCE as i can make it and still have something that comes close to working.
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott Kimberly wrote:How can you not answer this question based off of theories behind what im trying to do and how can you not do it off of the code i just provided?

Trust me, with the code you provided initially nobody could have helped you. That's because the problem isn't in that code but in class MyDrawing2. The JScrollPane uses the preferred size of the component inside the view port, and if you don't add anything to it that preferred size will be 0x0 pixels. In other words, the JScrollPane thinks the panel fits and doesn't need scroll bars.

The solution is very simple - add the following method to MyDrawing2:
This will cause the JScrollPane to see that the panel does not fit, and it will add the scroll bars as needed.

Just one question though - why don't you use a JLabel?
Voila, you get drawing and the size for free.
 
Scott Kimberly
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is why SSCCE isnt terribly useful to me.

My actual program reads in an image, subimages it, and them makes another image with that. It makes an image that is made up of images that are 64 pixels square.

So the image size i currently work with is 640 x 640 because of 4 methods that read in the file and store subimages in arraylists, make an BufferedImage[][] based off of the arraylists, stores that information in a different arraylist, and then reads that arraylist to actually display images.

So when i call my dimension method, what are my arguments for the new dimension?

And i dont use JLabels because i dont understand why i would ever need to? JPanel and JLabel were doing the same thing outwardly to me so i never saw a need.

EDIT: i made 2 variables that were the individual image width/height and multiplied it by the rows or cols variables i have (the same way i basically make the image with a for loop) and it works now. Those 2 variables are the arguments for dimension. Dimension is what i was looking for but never would have found in the API for JScrollPanes, or at least its in there and not obvious. Thankyou.
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!