Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with Applets & JLayeredPane

 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm very familiar with Java, just not Applet and GUI design. I'm having a lot of trouble getting my applet to work correctly. Ultimately I would like to have a basemap (map of some place) and then some icons that are visible on top of the map. So I figured I would use a JLayeredPane with the basemap at the lowest level and the icons on higher levels. Right now all I'm getting to display are the icons (which for now are just JLabels) and nothing else. I'm very frustrated...any help is appreciated.
My code follows:
 
Korol Bloom
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,
if your basemap is just an image, you don't need to use a layeredpane. You can take a normal jpanel and overwrite paintComponent(Graphics g).
e.g.

that would fill the whole Panel with the Image. The Icons just add as children to the panel.
, korol
 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Korol for the response. You said in your reply:

The Icons just add as children to the panel

Can you clarify? Again, I'm not the most familar with applet design. What do you mean add them as children? You mean add the icons (or other small images) to the Panel? Using what function call? Thanks for clearing it up.
 
Korol Bloom
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean, instead of

you can try

then you don't need the basemapLabel, and adjust the panel's paintComponent() as described above. Java will first call paintComponent() on your panel, then call the paint methods of its children. So your labels will be painted on top of the image.
, korol
 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Korol,
Thank you very much...it now makes a lot more sense.
 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more quick question...I would like to locate the icons by using an exact location rather than any of the layout managers. For example, I would like to be able to locate an icon at point (X, Y) on the map. I thought I could set it using the "label.setBounds()" method call, but this doesn't seem to work. Any other ideas? Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic