Is there anyway of actually changing the length of a slider. I have a some sliders in a grid layout and im wondering wether the grid layout will stop the sliders from expanding.

Recommended Answers

All 4 Replies

Controls will always take up all available room in a layout manager. That's guaranteed by the AWT API (on which Swing builds).
So your answer is no, you can't prevent the sliders from changing their size.

Darn so how can i make them bigger?! I feel the grid layout might be restricting the size but im not so sure.

A grid layout will give each element in it the exact same horizontal and vertical size.
If you don't want that (for example you want some controls to take up less space, think of a group of very short labels) you will have to use another layout manager that offers more flexibility like GridBagLayout.
Those are of course harder to use because of that greater flexibility.

You can still not control size directly but you can now say that your slider can run across multiple columns.

if you are usign a JSlider you can use setPreferredSize() to change the size, but if you are usign GridLayout then it will not expand over the "cell" you are in. You will have to use multiple layout managers to accomplish this goal while still maintaining your GridLayout

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.