简体   繁体   中英

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.

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?

ps (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM