Jump to content
  • Advertisement
Sign in to follow this  
joeyg2477

[java] using slider

This topic is 4554 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!