Help coderanch get a
new server
by contributing to the fundraiser
  • 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

aligning components

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i created a class that extends JPanel, and added a JComboBox to it. i (hopefully) made them the same size like so:

i then have another JPanel with a 2X2 GridLayout with JLabels in the top row and StandardColorSelector's in the second row. the Jlables are left aligned , but the StandardColorSelector's are centered. i tried to left align them like so:
private StandardColorSelector backcolor = new StandardColorSelector();
private StandardColorSelector forecolor = new StandardColorSelector();
.
.
.
forecolor.setAlignmentX(LEFT_ALIGNMENT);
backcolor.setAlignmentX(LEFT_ALIGNMENT);
but it doesnt work
i also tried this:

and this:

[ February 16, 2004: Message edited by: Randall Twede ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that the panels that hold the comboboxes are by default using FlowLayout, and FlowLayout by default is centered. You can change this by adding the line -

to StandardColorSelector's constructor.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nathan,
thanks, thats what i needed. i set it outside the class, but it worked.
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic