aspose file tools
The moose likes Swing / AWT / SWT and the fly likes JSlider question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JSlider question" Watch "JSlider question" New topic

JSlider question

Brandt Charles
Ranch Hand

Joined: Apr 17, 2006
Posts: 57

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.

Thanks in advance.


Green, green, green!
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
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.
wood burning stoves
subject: JSlider question