• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

trouble with my gui

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Play around with the other fields of the GridBagConstraints ... like anchor
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic