Question

So I'm trying to resize a JSlider which is in a layout manager. Because of this (or so I have heard) I need to set its preferred size. The setPreferedSize does not accept int, int as I expected, but instead accepts a dimension. My question is, how do I actually set the dimension?

I have tried:

dimension sliderLength = 500, 10

dimension sliderLength = (500, 10)

And I have tried

dimension sliderLength(500, 10)

All without success.

Was it helpful?

Solution

slider.setPreferredSize(new Dimension(500, 10));

or:

Dimension sliderLength = new Dimension(500, 10);
slider.setPreferredSize(sliderLength);

OTHER TIPS

You could do

JSlider slider = new JSlider() {

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(500, 10);
    }
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top