Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image lost behind buttons

 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class has moved onto adding buttons onto the window. Just prior to this we learnt to add an image via JComponent, then we added buttons onto a JPanel; the problem is that when I try to combine the two into a single window (my own desire, not part of the class) I completely lose whatever is added first. How can I add the buttons so that both the button and the graphic are visible (buttons on top of the graphic)?

 
Rob Camick
Ranch Hand
Posts: 2608
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I completely lose whatever is added first


Read the section from the Swing tutorial on Using Layout Managers.

The default layout manager for a frame is the BorderLayout. Where do components get added when you don't specify a constraint? What do you think happens when you try to add two components at the same place?

Either use proper constraints or use a different layout manager.
 
Maneesh Godbole
Saloon Keeper
Posts: 11085
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,
As you already know we have a forum dedicated for Swing. This question would have been more suitable there.
I will move it there for you.

http://faq.javaranch.com/java/CarefullyChooseOneForum
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic