I have both a horizontal and vertical JSlider. How do I increase the length of the slider? I want the same range of values, just need it to appear longer. I was checking out the inherited methods, even tinkered around with setSize() to no avail.
It seems like a simple question but the answer can be complicated. Some information: 1 — setSize is used mainly for top–level containers, has no affect on a component until after realization and maybe not then depending on the layout manager of its parent, and is used in absolute positioning (null layout). 2 — Swing components respond to the setPreferredSize method readily (by design). Use this to provide size information for parent containers which will use it for display. 3 — the layout manager(s) of the parent container(s) can have a lot to say about size hints. For example, FlowLayout respects a components preferredSize and attempts to display it at this size. Ditto for GridBagLayout unless you use constraints to control the size, egs, weight and/or fill constraints can be used to alter/control the display size of components. GridLayout ignores the preferredSize of its child components. BorderLayout: yes and no depending on the section. See the api discussion section for details on each layout manager. The tutorial has a lesson on layout managers that is helpful. So the answer will include the use of the preferredSize (sometimes minimum/maximum sizes, too) in judicious combination with one or more layout managers to get the layout and resizing behavior that you want. This takes some study and lots of practice.
Every plan is a little cooler if you have a blimp. And a tiny ad.