• Post Reply Bookmark Topic Watch Topic
  • New Topic

Panel from nested class does not display  RSS feed

 
Marcus Rauchfuss
Ranch Hand
Posts: 51
1
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have this panel in a nested class in the MainPanel class and it does not display, when I launch the applet, or more like, the two menus "LineColor" and "BackColor" from the nested class ColorPanel do not display .

This is the code:




Any hints what the problem could be?

 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using Panel rather than JPanel? AWT was virtually obsolete when I first learnt GUIs ten years ago. JPanel will probably be obsolete in three years, when we shall use JavaFX.

Do you know about top‑level containers? You can read about them in the Java Tutorials. There are four general kinds: applets dialogues windows and frames. Only those four kinds of container can be visible without being added to something else.

Why are you making the container implement those interfaces? You should separate the model from the display.
Why are you using the == operator on reference types?
 
Marcus Rauchfuss
Ranch Hand
Posts: 51
1
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell Ritchie,


this is a project exercise for the O'Reilly SOT Java3 course, and I am stuck with the problem I described.
It is actually a modification of the project from the previous lesson, so I am limited in the choices of things I can do.
 
Piet Souris
Rancher
Posts: 1783
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Marcus,

I don't see you adding anything to ColorPanel that has some size.
I suspect that the actual size in the main panel will be (0,0)
(width, heigth).

Can you override the setPreferredSize(Dimension d) to some
reasonable value? Give your ColorPanel an easy to reckognize
background color, and add a Button to it.

I bet you will see it appear. If not, let us know.

Greetz,
Piet
 
Marcus Rauchfuss
Ranch Hand
Posts: 51
1
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Piet, I actually got it working now. I programmed a regular class and it worked straight away, then I copied the class into the other and it still works. I am checking now, where the mistake was. :-)
 
Piet Souris
Rancher
Posts: 1783
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, Marcus.

Let us know, 'cause you made us curious!

greetz,
Piet
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!