Sign in to follow this  

[java] using slider

This topic is 4272 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im trying to implement a slider on a jframe and it's taking up the whole window. I've searched for information on it, but I can't find the imformation I need. So, how can I add a jslider to a jframe that only takes up a little space on the side of the window?

Share this post


Link to post
Share on other sites
The reason why it takes the whole window space is because of the Layout manager used. You should specify a (GridBag) layout manager to order your components and place them where you want them to be.

I'm fond of using a null layout manager - frame.getContentPane().setLayout(null) - and placing the components using X, Y, Width and Height. That keeps their position to where you want them, but the drawback is when you want to resize the window - which I usually disable when appropriate.

Son Of Cain

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
can u give me an example using frame.getContentPane().setLayout(null), where you use x,y,width, and height.

Say that I have:
JSlider slider = new JSlider();
how would you add that: starting at 0,0 and going to 100,50

Share this post


Link to post
Share on other sites

JFrame frame = new JFrame();
JSlider slider = new JSlider();

frame.getContentPane().setLayout( null );
frame.getContentPane().add( slider );
slider.setBounds(0, 0, 100, 50);

Share this post


Link to post
Share on other sites

This topic is 4272 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this