Jump to content
  • Advertisement
Sign in to follow this  
nihonlvr

[java] Java Problems

This topic is 4463 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
Advertisement

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
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!