Sign in to follow this  
nihonlvr

[java] Java Problems

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

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