C
Chris
I am having issues displaying two custom JComponents at the same time.
I have created a class which extends JWindow, and runs the following
code:
getContentPane().add(new CustomComponent(20,20));
getContentPane().add(new CustomComponent(120,20));
setSize(640,480);
setVisible(true);
The class CustomComponent extends JComponent and has the following
method:
protected void paintComponent(Graphics g)
{
g.fillOval(x,y,50,50);
}
The problem is that only the second CustomComponent added is
displayed. When the following code is run, there is no problem:
getContentPane().add(new CustomComponent(20,20));
setSize(640,480);
setVisible(true);
getContentPane().add(new CustomComponent(120,20));
setSize(640,480);
setVisible(true);
Note that BOTH setSize and setVisible must be run inbetween each
CustomComponent addition for them all to be displayed.
Can anybody shed any light on what's happening. I don't get this
problem when adding JLabel, so I guess it must be a problem with my
CustomComponent.
Thanks for your help.
I have created a class which extends JWindow, and runs the following
code:
getContentPane().add(new CustomComponent(20,20));
getContentPane().add(new CustomComponent(120,20));
setSize(640,480);
setVisible(true);
The class CustomComponent extends JComponent and has the following
method:
protected void paintComponent(Graphics g)
{
g.fillOval(x,y,50,50);
}
The problem is that only the second CustomComponent added is
displayed. When the following code is run, there is no problem:
getContentPane().add(new CustomComponent(20,20));
setSize(640,480);
setVisible(true);
getContentPane().add(new CustomComponent(120,20));
setSize(640,480);
setVisible(true);
Note that BOTH setSize and setVisible must be run inbetween each
CustomComponent addition for them all to be displayed.
Can anybody shed any light on what's happening. I don't get this
problem when adding JLabel, so I guess it must be a problem with my
CustomComponent.
Thanks for your help.