File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Help with simple GUI layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help with simple GUI layout" Watch "Help with simple GUI layout" New topic

Help with simple GUI layout

Joe Niksa

Joined: Feb 24, 2012
Posts: 12
I'm having trouble with making my JPanel look right. I am not very experienced with building GUIs yet. I've tried everything I could and now I need some major help. The JFrame is very simple looking. I got it as close as i could and then threw a screenshot in paint to modify it to how I want it to look. Can someone help me? I just want it to look very similar to the screen shot. But when the program starts, the green panel will be opaque, then after you click the button, depending on the result of the if-then statement I will write, it will either turn RED or GREEN. I know how to do that but I just need the actual layout corrected. Ignore the "fake" button i created. I was experimenting and it was the only way I could get the colored pane to show up on the bottom. I think my grid is just not formatted right.

Thanks for any help!

[Download untitled1.bmp] Download

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
probably not the simplest way to do it (and you'll need to test what you want done if the frame is dragged wider or leaner)
(if you need the button/textfield to be taller, just set their preferredSize.height)

Tony Docherty

Joined: Aug 07, 2007
Posts: 2839
GridLayout is a good layout manager if you want to layout components in a grid where every component is the same size. But the image you have provided suggests this is not what you want to do - you don't want a grid style layout and the components are not the same size.

There are lots of other Layout Managers available, some could handle this is one go (ie GridBagLayout) others would need to be used in combination (eg FlowLayout for the top line components, GridLayout for the panel holding the top line and the second line component and BorderLayout for the panel holding the upper components (NORTH) and the coloured area component (CENTER)).
Joe Niksa

Joined: Feb 24, 2012
Posts: 12
Thank you Michael! That is exactly how I want it to look. Thanks for the help.
I agree. Here's the link:
subject: Help with simple GUI layout
It's not a secret anymore!