This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.