• 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

How to group these JLabels?

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear friends:

I have following code, see below:




I hope to group 1, 2 or 3 or 4 JLabels together at my will, then I can move these whole group together as one JLabel, I am not sure I should use another JLabel to group or any other component to do this. but need:
[1]. all JLabels within this group should display
[2]. whole group can move as ONE JLabel
[3]. Each JLabel such as JLabel1, JLabel2, JLabel3 etc can move freely within this group JLabel Frame as they move before group. but cannot move out of boundary of group
[4]. I can add or remove this group JLabel at my will, after remove, all JLabels return to normal status.

If guru can advice some idea that will be wonderful.
Thanks

Michelle
[ June 05, 2007: Message edited by: girl sunny ]
 
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
Group them all within a JPanel.
 
Michelle Wang
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good idea, but how to Drag and drop a JPanel to group them?
thanks
 
Michelle Wang
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello sir,
I updated code as follows to group JLabels, seems short of something.



Actually I can select some labels here, but group not happen. what is wrong here??
thanks
 
Michelle Wang
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Friends:
I tried several days for this problem, but still cannot find solution.
can any guru throw some light??
Thanks
 
Michelle Wang
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greg's comment: "Group them all within a JPanel.", looks like not work properly after my many days trial. not sure use JPane or other component??
Thanks
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope to group 1, 2 or 3 or 4 JLabels together at my will, then I can move these whole
group together as one JLabel, I am not sure I should use another JLabel to group or any
other component to do this.

Since you probably want a non–opaque container I would try using a JComponent.
but need:
[1]. all JLabels within this group should display
[2]. whole group can move as ONE JLabel
[3]. Each JLabel such as JLabel1, JLabel2, JLabel3 etc can move freely within this group
JLabel Frame as they move before group.

Okay.
but cannot move out of boundary of group
I didn't do this but it is easy enough to implement. In the mouseDragged method you can
check to see if the new position puts the dragged label out of bounds of its parent and,
if so, do not update the position.
[4]. I can add or remove this group JLabel at my will, after remove, all JLabels return
to normal status.

I don't understand this.
Here's an exploration of what (I think) you are trying to do.
When the toggle button is selected you can select (click on) labels to add them to the
group container. De–selecting the toggle button ends the process. Since the group
container consumes mouse events for use in moving its children it must re–dispatch events
to its parent container to facilitate its being dragged inside the parent.
 
Michelle Wang
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much, it is wonderdful!
reply
    Bookmark Topic Watch Topic
  • New Topic