Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

JSlider question

Ranch Hand
Posts: 57
IntelliJ IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Garden Master Course kickstarter
    Bookmark Topic Watch Topic
  • New Topic