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 Grid Bag Constraints Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Grid Bag Constraints" Watch "Grid Bag Constraints" New topic
Author

Grid Bag Constraints

Scott Upton
Greenhorn

Joined: Aug 08, 2012
Posts: 3
Hello! I am really confused here. For some reason, my output constantly justifies my first JLabel to the center. I'm not quite sure how to fix this; my professor told me to maybe try to left justify, but I tried that and it didn't do anything... I think it has something to do with my weightx and y. Sorry, I am genuinely new to Java and this site in general, and my code probably doesn't look very good at all, but any help with this would be much appreciated! Thank you! Here is the link to the relevant class: http://pastebin.com/vBSNmG0p
Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 531
    
    3

Scott, I know this isn't addressed to your question, but your LoanCalculatorPanel object extends ActionListener without providing the required implemenation of ActionPerformed. You might want to take care of that.

Couple of thoughts: First, can you trim your LoanCalculatorPanel object down the least code necessary to show the problem? Second, can you provide a JFrame parent (or something like that) in your posted code, so others could actually run it? Might be able to do more for you under those circumstances.

Don't feel bad if the GridBag seems tough. It is tough.
Scott Upton
Greenhorn

Joined: Aug 08, 2012
Posts: 3
Nevermind! I figured it out thanks!
Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 531
    
    3

Good work!

What did the problem turn out to be?
Scott Upton
Greenhorn

Joined: Aug 08, 2012
Posts: 3
I had to add c.fill = GridBagConstraints.HORIZONTAL; before I added the loan amount label to the panel, though I am still not quite sure why...
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Scott Upton wrote:I had to add c.fill = GridBagConstraints.HORIZONTAL; before I added the loan amount label to the panel, though I am still not quite sure why...

Join the club. I think GridBagLayout was put on earth to see just how arcane you could make a foundation class before you start causing mass suicide.

One thing you might want to do is look at BoxLayout. It seems to handle quite a lot of the things that GBL does, and it's a lot more intuitive.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Grid Bag Constraints