?
Solved

Vertical Layout & Scrolling Issue

Posted on 2006-10-25
9
Medium Priority
?
428 Views
Last Modified: 2012-06-27
Hi,

I have been having problems achieving the layout i want. My main panel is set to BorderLayout, i have a panel in the center and one on the left. This left panel is going to be a toolbox. I basically want the left panel to be 150px wide and simply have a column of buttons. I want each button to take up the whole 150px width. When the frame is resized and all of the buttons cant be displayed, i want a vertical scrollbar to appear.

I have tried using a toolContainer panel with FlowLayout, manually setting the preferred sizes of the buttons to 150px wide and setting the preferred size of the toolContainer to 150px width and 50px height (because im not really sure how many buttons i will have). This gives me the exact look im looking for, however, when i add a JScrollPane, because i've manually set the height of the toolContainer to a value, the scrolling doesnt kick in until the frame is less than the preferred height of the toolContainer. I'm not sure if this is the best method, but i tried setting up a loop that gets the height of all the components in the container and setting that as the preferred height and that seemed to work. So if there is a better way of creating this layout i'd love to know!!

But my main problem is that the scrollbars are acting very erratically. When the vertical scrollbar appears, it appears on the outside of the scrollpane (eg. there is 150px + width of the scrollbars), but then if i resize the frame just a little bit more, the scrollbar flicks to inside the panel (eg. width of container is 150px - width of scrollbars). Ideally i would always like the scrollbar to appear outside. Is there someway of controlling this?

I hope i've explained myself correctly!

Kind Regards,
Michael
0
Comment
Question by:Xavior2K3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 14

Expert Comment

by:hoomanv
ID: 17805150
I usually use TableLayout for complex guis
https://tablelayout.dev.java.net/
0
 
LVL 15

Accepted Solution

by:
Javatm earned 2000 total points
ID: 17805438
0
 
LVL 1

Author Comment

by:Xavior2K3
ID: 17805466
Does gridbag not act like gridlayout in such a way that if i add lots of buttons, instead of the containerpanel getting larger, it reduces the size of the cells to fit everything, and hence the buttons get smaller?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Expert Comment

by:Javatm
ID: 17806330
Gridbag is perfect in almost all aspect, you define all x and y location and the size of your component ;)
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 17806363
TableLayout can do whatever Gridbag is able to do and much more using less effort
0
 
LVL 1

Author Comment

by:Xavior2K3
ID: 17807672
Ok, i'll have a look into gridbag and tablelayout. What about the scrolling issue?
0
 
LVL 15

Expert Comment

by:Javatm
ID: 17812282
can you post a screenshot of your scrollbar?
0
 
LVL 1

Author Comment

by:Xavior2K3
ID: 17833017
Hey, I have figured out what my problem was. Firstly I set all of the buttons perferred, maximum, and minimum size to the same dimension (Box layout seems to stretch and shrink things accordingly). Once i had fixed sizes the scrollbar seemed to work consistantly.

Does anyone know how you can set preferred heights but leave the layout manager to adjust the widths? This way when a scrollbar appears on the right, componants widths will be reduced to acommodate the scrollbar?
0
 
LVL 15

Expert Comment

by:Javatm
ID: 17833941
Gridbag is the solution ;) you can also try the new layout presented in netbeans.
http://www.netbeans.org/kb/articles/matisse.html
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question