Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JLabel on top of JLabel

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JPanel that I am adding JLabels onto that contain an ImageIcon. There are times when I need to place a new JLabel on top of another JLabel but without removing one.
The one I place on top always get's placed underneath the first JLabel. I have tried Integer.MAX_VALUE and Integer.MIN_VALUE but it isn't working.
Any ideas?

------------------
Happy Coding,
Gregg Bolinger
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still waiting to see if anyone knows the answer to this. If you do, please reply. It would be greatly appriciated.
Thanks

------------------
Happy Coding,
Gregg Bolinger
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Greg,
Even im trying to to get a soln this problem, I know its too late, but I found ur messg using the Search option, I'm using labels with images, & the new label gets added below the first one..any ideas?
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do u try to add one label on top of another label?
wouldn't it be easier to just change the icon and the text in the label?
 
Sayed Ibrahim Hashimi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not really sure if this will help you but cant you use CardLayout to display different Components.
Bascially if you want to display 3 different sets of Components then you will create 3 "Cards". These cards can take the same space in a Component but only one will be displayed.
So if you want to have a label on top of another then create different "Cards" and display the one you want.
Hope this helps.
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No guys,
What I want to do is display a component over a component..its like a chair over a floor, i need to display the floor as well as the chair, but with JLabels having an image,the chair goes under the floor..hope u all get the idea
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My whole reasoning was for cards layed out over each other but cascading.
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my limited experience with Java, it is not possible to display one component on top of another in the same panel/container.
I believe it is possible to place the two components into two panels and switch between the panels using cardlayout.
I hope this helps.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the JLayeredPane API... it was made for just this kind of thing... run the example code below to see a JLayeredPane in action...



-Nate
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic