Sign in to follow this  

[java] Java Problems

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

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));
drawingArea.setBackground(Color.black);




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."

Regards,

GCS584

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