Re: Problems with JPanel and Graphics
From: Knute Johnson (nospam_at_sagebrush.frazmtn.com)
Date: 01/22/05
- Next message: SD: "Re: What happened? My "https applets" stopped working"
- Previous message: Princess Morgiah: "Re: [Process] I don't understand where is the problem"
- In reply to: bunallo: "Re: Problems with JPanel and Graphics"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 22 Jan 2005 11:08:25 -0800
bunallo wrote:
> That does not help I still don't get anything blue in the bottom or to the
> left (only white if I pull the frame).
Your code is missing a few parts like the import statements and the
main(). But that aside you can't see the JPanel because the JFrame is
obscuring it. Add a setPreferredSize() to your constructor to tell the
layout manager what size to layout the JPanel. Then call pack() instead
of setSize() on your frame. You will still probably have a funny
looking frame with some white space because the JPanel is smaller than
the frame's header.
--
Knute Johnson
email s/nospam/knute/
import java.awt.*;
import javax.swing.*;
public class Land extends JPanel {
public Land() {
setPreferredSize(new Dimension(100,100));
JFrame my_frame = new JFrame();
my_frame.getContentPane().add(this);
my_frame.setTitle("Field");
// my_frame.setSize(100,100);
my_frame.pack();
my_frame.setVisible(true);
}
public void paintComponent(Graphics g) {
g.setColor(Color.BLUE);
g.fillRect(0,0,100,100);
g.setColor(Color.GREEN);
g.fillRect(5,5, 90,90);
}
public static void main(String[] args) {
new Land();
}
}
- Next message: SD: "Re: What happened? My "https applets" stopped working"
- Previous message: Princess Morgiah: "Re: [Process] I don't understand where is the problem"
- In reply to: bunallo: "Re: Problems with JPanel and Graphics"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|