Re: Justifying box components
- From: RedGrittyBrick <RedGrittyBrick@xxxxxxxxxxxxx>
- Date: Wed, 07 Nov 2007 10:01:33 +0000
Michael Dunn wrote:
"H.L" <H.L@xxxxxxxxxxxxx> wrote in message news:47309CF9.4432@xxxxxxxxxxxxxxxx
I want to put a JSlider underneath a label explaining what it is there
for. I have used a Box object instantiated with the createVerticalBox
constructor. The problem is that the text and the slider has a bad
alignment. Is there any way to make them both centered or justified to
either side of the column? Thanks in advance.
if the label is off to the right a bit, add this line
slider.setAlignmentX(0);
but it still might not suit, as the label will appear a bit left of the start of the slider track
if you want them centered, add both lines
slider.setAlignmentX(.5f);
label.setAlignmentX(.5f);
There are some constants that I find handy for this:
slider.setAlignmentX(Component.CENTER_ALIGNMENT);
label.setAlignmentX(Component.CENTER_ALIGNMENT);
If I need to justify a large number of components, I use a for loop:
for(JComponent c: new JComponent[]
{ slider, label, this, that, other })
c.setAlignmentX(Component.CENTER_ALIGNMENT);
.
- References:
- Justifying box components
- From: H.L
- Re: Justifying box components
- From: Michael Dunn
- Justifying box components
- Prev by Date: Re: JDesktop Web Component Crashing
- Next by Date: How to scroll a table with a overlaid component
- Previous by thread: Re: Justifying box components
- Next by thread: JDesktop Web Component Crashing
- Index(es):
Relevant Pages
|