Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with Layout issues  RSS feed

 
tom davies
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create a layout but i cant get the components to align how i want.

I have attached an image showing the current layout. I want the text areas to move to the left and line up close to the labels without the big gap in between. I have tried using various gridbagconstraints but nothing seems to work how i want. I have also tried adding a new JPanel in borderLayout west position but that makes the text areas about 1 character wide.
I have added the current layout code below.

Screen Shot 2013-03-17 at 13.46.09.png
[Thumbnail for Screen Shot 2013-03-17 at 13.46.09.png]
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have got some confusing names for your text fields. Which is fromDate and which is StartDate (‍)?
Have you given those components preferred sizes? Have you put fill parameters in the constraints? Are you aware of Horstmann’s GBC class?
 
tom davies
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You have got some confusing names for your text fields. Which is fromDate and which is StartDate (‍)?
Have you given those components preferred sizes? Have you put fill parameters in the constraints? Are you aware of Horstmann’s GBC class?


Sorry, group project and i didn't write this section, im just trying to sort the layout out.
I have tried adjusting the fill constraints with no success. I will have a look at the link and also setting the preferred sizes.
 
tom davies
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have managed to achieve the layout using a blank JPanel with a set size which i put into the the grid sections to the right of the components, this is by no means a great solution but it works for now, until i can think of a better one
 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tom davies wrote:I want the text areas to move to the left and line up close to the labels without the big gap in between.

1) Set weightx = 0 for the labels (gridx = 0) and weightx > 0 for the text fields (gridx = 1).
2) Set gridwidth = 2 for resultsFormat (if that's the child panel with the radio buttons)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!