• 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 issues

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the deal. I have two JLabels. One of them is a large image.

When I click on the smaller label, it is 'glued' to the mouse. Meaning it moves to where ever the mouse pointer takes it.
When the mouse is clicked again, the label is 'unglued' and stays where it was dropped.

The idea is that this small label needs to be dropped onto the large label.
The problem is that the small label is behind the large label. I cant seem to bring it to the front.

I'm not using a layout manager (setLayout(null)).

Any ideas?

Thanks.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings, Wayne. Welcome to JavaRanch!

Please CarefullyChooseOneForum when you post a question. Posting your question to the right forum helps keep it well organized, and everybody can benefit from the discussion. Since this has more to do with Java Swing, let's slide it over there
 
Wayne Sheets
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roberto Perillo wrote:Greetings, Wayne. Welcome to JavaRanch!

Please CarefullyChooseOneForum when you post a question. Posting your question to the right forum helps keep it well organized, and everybody can benefit from the discussion. Since this has more to do with Java Swing, let's slide it over there



Understood. Thanks.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add your larger JLabel first, then the smaller. The last added component is drawn over the previously added component.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The last added component is drawn over the previously added component.


Sorry, Rob, it's the other way round. The first added Component is painted on top of any added later. That can be seen in the SSCCE that follows. However, even this behavior, though not in the least bit likely to ever change, is undocumented.

The recommended way to achieve desired stacking, or Z-Order is via the method setComponentZOrder(...).To see the desired stacking order, uncomment lines 56 and 57.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Darryl Burke wrote:

The last added component is drawn over the previously added component.


Sorry, Rob, it's the other way round. The first added Component is painted on top of any added later. That can be seen in the SSCCE that follows. However, even this behavior, though not in the least bit likely to ever change, is undocumented.


Huh, I could have sworn I've seen it work the other way around. But I just checked the source of JComponent and it does indeed go through the children backwards when painting.
 
Wayne Sheets
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the answers guys. It helps a lot!

[EDIT] A forum that links grammatically incorrect words! Awesome!
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wayne Sheets wrote: . . . a lot! . . . A forum that links grammatically incorrect words! Awesome!

Not after you correct the error. That is, by the way, the only grammatical error we flag like that.
 
reply
    Bookmark Topic Watch Topic
  • New Topic