How to adjust the size of Jsliders in Java?
How can I elongate sliders length and also the width if possible. Most importantly, the length.
Be开发者_如何学Clow 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.)
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.
精彩评论