tags:

views:

20

answers:

1

How can I elongate sliders length and also the width if possible. Most importantly, the length.

Below is just pieces of codework on Jsliders.

slider = new JSlider(0,180);
     slider.setMajorTickSpacing(30);
     slider.setMinorTickSpacing(15);
     slider.setPaintTicks(true);
     slider.setPaintLabels(true);
      slider.setValue(0);
 JPanel panel = new JPanel();
    panel.add(slider);

I tried doing slider.setSize(100,100); something like that, but that does not seems to be working. Any suggestions?

p.s (I was also wondering if the color encoded on the slider bar can be filled in with a different color like cyan, and if it exceeds some value, possibly change to red. Right now it is set to default, it gets filled with light blue.)

+2  A: 

To change the size of a Swing component you use setPreferredSize(), not setSize(). The layout manager will either use the "suggested" preferred size or ignore it.

Some LAF will use the UIManager to determine the colors used for painting components. If you want to change the color for all JSliders then check out the UIManager Defaults for a list of properties you might be able to change.

camickr
Thanks, I did slider.setPreferredSize( new Dimension( 800, 80 ) ); and it worked.
Faraz Khan