Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with simple GUI layout

 
Joe Niksa
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Filename: untitled1.bmp
Description:
File size: 425 Kbytes
[Download untitled1.bmp] Download Attachment
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2969
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Michael! That is exactly how I want it to look. Thanks for the help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic