Re: Justifying box components



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);
.



Relevant Pages

  • Re: Slider Bar for Survey
    ... there are third party controls for this e.g. Microsoft Slider ... Control that you may have installed on your system. ... Place a label over the line (background ... Private Sub lblBackground_MouseDown(Button As Integer, Shift As Integer, X ...
    (microsoft.public.access.forms)
  • Slider control and Mouse Wheel
    ... Stick a slider from Common controls 6.0 on a form, set the min,max ... When you use the mouse wheel to alter the slider the label changes to echo ... except at zero when the scroll event seems not to fire. ...
    (microsoft.public.vb.general.discussion)
  • Re: Mathematica: How to force manipulate to accept only discrete values from user?
    ... I am trying to write a manipulate which will accept only integer values. ... Now, if I move the slider above, the value do change in discrete amount by ... but this option will prevent the label from showing on the right side ... will also automatically change the contents of the input field. ...
    (sci.math.symbolic)
  • Re: Slider Bar for Survey
    ... I was able to replicate this slider control and it works well. ... > Place a label over the line (background ... > Private Sub lblBackground_MouseDown(Button As Integer, Shift As Integer, X ...
    (microsoft.public.access.forms)
  • Re: Justifying box components
    ... constructor. ... The problem is that the text and the slider has a bad ... alignment. ... but it still might not suit, as the label will appear a bit left of the start of the slider track ...
    (comp.lang.java.gui)