Jump to content
  • Advertisement
Sign in to follow this  

[java] Java Problems

This topic is 4557 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

I am pretty new to Java and am having a difficult time working with JComponents. What I am trying to do is create a class that creates a JPanel object that is 50 pixels by 50 pixels and sets the background color to black. Can anyone point me in the right direction?

Share this post

Link to post
Share on other sites

import java.awt.*;
import javax.swing.*;


JPanel drawingArea = new JPanel();
drawingArea.setPreferredSize(new Dimension(400, 0));

As Sun's Java tutorial page on layout managers states:
"Or you can create a subclass of the component that overrides the appropriate getter methods — getMinimumSize, getPreferredSize, and getMaximumSize."

But remember: "Many layout managers don't pay attention to a component's requested maximum size. However, BoxLayout and SpringLayout do."



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!