>I am having issues displaying two custom JComponents at the same time.
...
>Can anybody shed any light on what's happening.

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Sorry, here's a better 'SSCCE' as you put it:
---------
public class CustomComponent extends JComponent
{
protected int x, y;
CustomComponent(int x_in, int y_in)
{
x = x_in;
y = y_in;
}
protected void paintComponent(Graphics g)
{
g.fillOval(x,y,50,50);
}
}
public class Test extends JWindow
{
public static void main(String[] args)
{
getContentPane().add(new CustomComponent(20,20));
getContentPane().add(new CustomComponent(120,20));
setSize(640,480);
setVisible(true);
}
}
--------
I'm not using a layout, is one required?
I don't know what you mean by the preferred size. I have not come
across this.
>> Can anybody shed any light on what's happening.
> Is that a question?
Yes, if you add JLabels to the content pane instead of the
CustomComponent class, the above code works fine. I am confused about
why it does not like more than one of my classes.
Lew - 16 May 2007 15:23 GMT
> Sorry, here's a better 'SSCCE' as you put it:
Did you /read/
<http://www.physci.org/codes/sscce.html>
?
> # Self Contained - Ensure everything is included, ready to go.
> # Correct - Copy, paste, (compile,) see is the aim.
With respect to your "SSCnon-CE":
> ---------
>
[quoted text clipped - 26 lines]
>
> --------
Did you notice the compiler errors? (I called the test class
"CustomComponentTester" to avoid name conflicts.)
Actual compiler errors:
Compiling 1 source file to projects/testit/build/classes
projects/testit/src/testit/CustomComponentTester.java:9: non-static method
getContentPane() cannot be referenced from a static context
getContentPane().add(new CustomComponent(20,20));
projects/testit/src/testit/CustomComponentTester.java:10: non-static method
getContentPane() cannot be referenced from a static context
getContentPane().add(new CustomComponent(120,20));
projects/testit/src/testit/CustomComponentTester.java:11: non-static method
setSize(int,int) cannot be referenced from a static context
setSize(640,480);
projects/testit/src/testit/CustomComponentTester.java:12: non-static method
setVisible(boolean) cannot be referenced from a static context
setVisible(true);
You saw these same errors when preparing your "SSCCE", right?
Here's the clue to interpreting the "non-static method ... referenced from a
static context" message: From what object are you trying to getContentPane()
and the others?
Was this how your original code was? Did it, too, call non-static methods
from a static context?

Signature
Lew