• Post Reply Bookmark Topic Watch Topic
  • New Topic

Placing a component on top of other components

 
george justin
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
i am not able to place/insert any componet on top of other components during runtime; if i try to place it, it goes behind the existing components, i know it could be done using java.awt.window. Using its toBack(),toFront() methods i can control the look, but its not possible using Canvas or other components.Could someone suggest an alternative. should i be repainting the whole panel where components r placed.......
a urgent reply will be highly appreciated
thanx
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just figured it out.
When you add your component, do this.
JButton jo = new JButton(null, myIcon);
int toTop = jo.TOP;
myJPanel.add(jo, toTop);
The .TOP returns an integer and tells JAVA to place this component on top of the highest component every time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!