File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes trouble with my gui Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "trouble with my gui" Watch "trouble with my gui" New topic
Author

trouble with my gui

Jason McKinley
Greenhorn

Joined: Jun 27, 2013
Posts: 18
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

Joined: Oct 16, 2003
Posts: 1075
    
  10

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:


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Jason McKinley
Greenhorn

Joined: Jun 27, 2013
Posts: 18
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

Joined: May 03, 2008
Posts: 4523
    
    5

Play around with the other fields of the GridBagConstraints ... like anchor


luck, db
There are no new questions, but there may be new answers.
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1075
    
  10

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

Joined: Jun 27, 2013
Posts: 18
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

Joined: Jun 27, 2013
Posts: 18
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

Joined: Oct 16, 2003
Posts: 1075
    
  10

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: trouble with my gui
 
Similar Threads
How to add Jseprator in gridbag layout
Creating and opening a window if the button is clicked in an applet
GridBagLayout
problem in layout a form.
Swing, ActionEvent can't see button...