• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JLabel on top of JLabel

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic