Forums Register Login

Swing - valign

+Pie Number of slices to send: Send
Hi, I have problems with swing again! It hates me and I hate it too...

I have 3 items in a FlowLayout. But they seem to be middle valigned. How do I make them align to the top???

Thank you!!
+Pie Number of slices to send: Send
Hi Anna,

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,

Greg

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 ]
+Pie Number of slices to send: Send
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!!!
+Pie Number of slices to send: Send
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 ]
I'm sure glad that he's gone. Now I can read this tiny ad in peace!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 976 times.
Similar Threads
Creating GUIs on MAC OS X
Music transcription program
Stereotype of java application
Inner Classes when to use them?
Change jLabel properties in loop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:15:49.