• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Swing - valign

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Greg Till
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic