• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

trouble with my gui

 
Jason McKinley
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I new here and needed some help on a simple program I am writing to help me learn java. It's a small and simple address book program, I am making the gui and was testing it out to see what it looks like. My problem is that when I run it to test the gui everything pops up in the middle. Could someone tell me what I am doing wrong/ not doing to cause this. I would like to see everything at the top. I have tried changing the gbc.fill = GridBagConstraints.HORIZONTAL from horizontal to northwest to see if that worked but it just caused other problem. Anyway here the code:



Thanks in advance for the help and if you need anything else let me know.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jason,
Welcome to the Ranch!

You can use one dirty trick to achieve this - set the weighty to 1.0 just before the last component, like:
 
Jason McKinley
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranganathan Kaliyur Mannar wrote:Hi Jason,
Welcome to the Ranch!

You can use one dirty trick to achieve this - set the weighty to 1.0 just before the last component, like:


I tried what you suggested but the only problem with that is that it puts the separator halfway down the program.
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Play around with the other fields of the GridBagConstraints ... like anchor
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason McKinley wrote:I tried what you suggested but the only problem with that is that it puts the separator halfway down the program.

I ran it again and I don't have that problem. i.e. the separator appears right after the buttons for me.

Btw, I just found that you call the AddressBook at the end after calling setVisible(true). This is not the right way to build GUI in Swing. You build the GUI and call make it visible at the end.
(and btw, AddressBook() is a bad name for a method- same as class name and static-you should really change that)
 
Jason McKinley
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Play around with the other fields of the GridBagConstraints ... like anchor


Went to bed thinking about what you said and woke up and had the fix right in my head lol. it works great now, time to move on to my other part of the gui.
 
Jason McKinley
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranganathan Kaliyur Mannar wrote:
Jason McKinley wrote:I tried what you suggested but the only problem with that is that it puts the separator halfway down the program.

I ran it again and I don't have that problem. i.e. the separator appears right after the buttons for me.

Btw, I just found that you call the AddressBook at the end after calling setVisible(true). This is not the right way to build GUI in Swing. You build the GUI and call make it visible at the end.
(and btw, AddressBook() is a bad name for a method- same as class name and static-you should really change that)


That's strange, every single time I ran it, it came up in the middle. At any rate, as I stated above, I got it fixed now. Also thanks for the advice you gave me, I am totally new to all java and programming as a whole and am learning this on my own. Any help I can get, I am grateful for.

Anyway, thanks to everyone for the help.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic