It's a little difficult to picture your problem without seeing your code, but the way I make things vertically aligned to the top is to set the Layout manager for your container to BorderLayout, add a new container to it in the NORTH position and then add your components to this new container.
So if you were adding a button to a JFrame -
Hope this helps,
PS swing is tricky to get the hang of, but it is a beautiful thing once you get the hang of it! [ May 19, 2004: Message edited by: Greg Till ]
Joined: Nov 09, 2003
I wanna valign 3 components to the top, top left, top middle and top right, not just one component. ;( How do I do that? Sorry it is not clear, got a large amount of code, thot it won't look good here.
PS swing is tricky to get the hang of, but it is a beautiful thing once you get the hang of it!
I hope that is true so much. I feel it is bit easier now, but far from beautiful...I want to do the GUI in Flash!!!
Joined: May 10, 2004
OK, I think I can see what you are trying to do (had to enclose this not-so-pretty picture in code tags to make it display) -
Think components within components (or specifically JPanels within JPanels) until you get what you want. To have one control top left of the screen, one control top middle and one control top right of the screen, I would -
Set the Layout Manager for the JFrame's content pane to BorderLayout Create a JPanel to sit along the top (North) border of the screen - and set the Layout of this to BorderLayout
Create three more panels and add these to the top panel in EAST, CENTER and LEFT position. Add the top panel to the JFrame in North position. Your 3 sub-panels will now be top left, top middle and top right of the screen. You can add controls to them as you wish.
If you need to do anything more complicated, you might want to start looking at GridBagLayout or SpringLayout - and you can always combine these with other layouts.
[ May 19, 2004: Message edited by: Greg Till ] [ May 19, 2004: Message edited by: Greg Till ]