0

I dont intend to throw code at you and ask you to complete it. Unless the following makes no sense in which case code may be a lot of help.

I have a JFrame set that has a scrollbar and 12 buttons on it in a GridLayout(12x1). Each button has a panel which displays different things.

The last button/panel changes size when an image is chosen from filechooser and displayed. But that last panel becomes too big and I cant scroll down to see the rest of it. I am left with just half the last panel. I have tried resize() and setPreferredSize() to the frame, scrollbar and jpanel but I dont think any are working :(

Can anyone offer some insight through personal experience or do you just know what I could do to fix this problem?

http://oi59.tinypic.com/r0us79.jpg

I could not upload pictures here so I used tinypic. This shows my problem example with before and after. Notice how the scrollbar is at maximum in both images.

SOLVED: I have been able to view the whole panel now by increasing the size of the scrollbar panel. However this also makes all other panels increase in size. If anyone knows how I can increase the scrollbar so that only that one panel increases that would be nice.

user3397180
  • 51
  • 1
  • 1
  • 5
  • 1
    Please edit your question to include an [mcve](http://stackoverflow.com/help/mcve) that exhibits the problem you describe. In your example, access posted images via `URL`, as shown [here](http://stackoverflow.com/a/10862262/230513); use synthetic images as shown [here](http://stackoverflow.com/a/15982915/230513); or use `UIManager` icons, as shown [here](http://stackoverflow.com/a/12228640/230513). – trashgod Mar 23 '14 at 19:18
  • 2
    `I have tried resize() and setPreferredSize() to the frame, scrollbar and jpanel but I dont think any are working` - Don't do any of that. Use layout managers and scrollBars will show when needed. – camickr Mar 23 '14 at 19:40
  • How do you suggest I fix my issue then with the GridLayout or JScrollbar in place? – user3397180 Mar 23 '14 at 19:49
  • 1
    First of all follow @trashgod advice, try to post a complete and minimal example that demonstrate the problem you are facing. That will be very helpful, and the answer is probably what camickr says as a comment – nachokk Mar 23 '14 at 19:50
  • There is no such thing as a complete AND minimal example. If you want code you have to see it all. As if I understood where this went wrong I wouldnt need to ask for help. But I still have the problem, so what did you want me to do with the layout manager? – user3397180 Mar 23 '14 at 19:57
  • 1
    `There is no such thing as a complete AND minimal example.` - Yes there is. For example each of your current panels has about 7 components added to the. Are the components the problem? If not, then don't add them. The point of a [SSCCE](http://www.sscce.org/) is to demonstrate the problem with the least code possible. That is do some basic debugging and get rid of code an components to see if they are causing the problem. Eventually you will get to a point where you can demonstrate the problem in 20-30 lines of code, that is if you truly understand the code you are writing. – camickr Mar 24 '14 at 00:01
  • 1
    `I have been able to view the whole panel now by increasing the size of the scrollbar panel.` - wrong solution. I already told you that you should NOT be attempting to manipulate the size of any component. The scrollbars appears automatically when the preferred size of the component added to the scroll pane is greater than the size of the scroll pane. When you use a layout manager the preferred size of the panel is calculated dynamically as you add components to the panel and then `revalidate()` the panel. – camickr Mar 24 '14 at 00:03
  • I always draw my screen, as I want it to look. So I can analyze which components need to be in the same panel, and what layout managers i need to use, on all the different panels. check [layout managers](http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html), [about JScrollPane](http://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html) and [borders](http://docs.oracle.com/javase/tutorial/uiswing/components/border.html). – SuperRetro Mar 24 '14 at 15:52
  • Personally, I use almost always, a combination of BorderLayout (for the mainPanel), BoxLayout (for positioning components in one line, next to each other horizontally or vertically, also handy for laying out buttons in a panel), GridLayout (for creating equal sized components) and GroupLayout (for creating nice blocks of inputfields and labels). – SuperRetro Mar 24 '14 at 16:01

0 Answers0