Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing component alignment

 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can someone tell me how to align components within a panel please?
I have 3 little panels in a big panel and I want to align all the little panels left in the big panel. I have been search thru for the past hour and still not much clue! I use JPanel.
Thanks
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just found this about the SpringLayout. I'm just taking a the look at the GUI side of the assignment myself so don't follow my suggestion blindly. There may be simpler ways.
There is also the BoxLayout which can align its managed components.
But JPanel inherits from JComponent which has setAlignmentX() and setAlignmentY() methods, so JPanels inside JPanels maybe the simplest way to go.
[ April 19, 2004: Message edited by: Barry Gaunt ]
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried a couple of layouts and setAlignmentX, dont seem to work...So I guess I must have missed something... The SpringForm tutorial seems got the way, but it looks complicated, so I am thinking there must be an easier way like the setAlignmentX function...??
Or does setAlignmentX only works for certain layouts?? I only tried for FlowLayout and the default layout on JFrame (forgot what it is).
*Confused*
[ April 19, 2004: Message edited by: Anna Kafei ]
 
Anna Hays
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AH HA! Works now... I was setting the alignment on the JPanel instead of on the layout. Duh!
Thanks for your post!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just read that the attributes set by setAlignmentX() and setAlignmentY() are used only by the newer Layout Managers (such as BoxLayout) and are ignored by older ones.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic