Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to group these JLabels?

 
Michelle Wang
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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 ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Group them all within a JPanel.
 
Michelle Wang
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks so much, it is wonderdful!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic