If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Java Component Alignment Trouble

I was wondering if anyone can shed any light on the following problem I've been having. I finally stumbled upon the GridBagLayout manager and now do not need to suffer stretched components being displayed on my screen, but the problem that I'm having is that the GridBagLayout is centering the components on the screen when I want them placed in the top left hand corner like this ascii diagram shows:

I'm not sure how to change this as I cannot find any methods or public vars that I can use/change to alter where the components are placed. And yes, I have searched through the java api extensively and searched google and the sun java site.

Death_Knight, using a BoxLayout solved the problem I posted above, the only problem I have now is that before the labels stretched horizontally so that if you changed the background colour of the label to be different from the background colour of the panel it was added to, the colour would stretch to the end of the panel, now that's not happening. meh! Solved one problem and made another. :P

What if none of the components has a maximum width? Well, if all the components have identical X alignment, then all components are made as wide as their container. If the X alignments are different, then any component with an X alignment of 0.0 (left) or 1.0 (right) will be smaller. All components with an intermediate X alignment (such as center) will be as wide as their container. Here are two examples:

Amazing...I had actually skimmed that and tried changing the Maximum size of my labels but because I didn't set the alignment of them, it didn't change the size correctly. For some reason I just assumed it couldn't have been an alignment issue.

BTW -- if anyone is interested, I'm attaching the program. It's not nearly finished yet, but just so that you can see what I was trying to do. To be honest, the gui is not meant to be taken seriously, it was meant to be a bad joke (one that I won't explain); in fact, I find it ironic that in creating this gui, I'm basically emulating an old dos application :P

The most interesting part of the program is the Menu class which creates a menu by parsing the code written in the menu file (which is changed at the moment by changing the value of a constant in the Menu class.

I want to stress that the program isn't finished...I've still got to add stuff and clean up the mess that MenuGame.java got into from me trying out different layout managers and weird things.

The two menu files included are MENU.txt and JOYCE.tst. And if you're wondering where I got the sad idea for the gui, it's the till system we use at my work (or my copy of it)

I didn't, but it doesn't matter because I got the program to do what I want now. I've tried using JBuilder before (just messing about really), but I don't like the way it works (from what I've seen). I quite like the fact that in java it's relatively easy to code fairly complicated GUIs by hand.