aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to group these JLabels? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to group these JLabels?" Watch "How to group these JLabels?" New topic
Author

How to group these JLabels?

Michelle Wang
Ranch Hand

Joined: Apr 17, 2007
Posts: 87
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15290
    
    6

Group them all within a JPanel.


GenRocket - Experts at Building Test Data
Michelle Wang
Ranch Hand

Joined: Apr 17, 2007
Posts: 87
good idea, but how to Drag and drop a JPanel to group them?
thanks
Michelle Wang
Ranch Hand

Joined: Apr 17, 2007
Posts: 87
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

Joined: Apr 17, 2007
Posts: 87
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

Joined: Apr 17, 2007
Posts: 87
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

Joined: Jan 14, 2004
Posts: 1535
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

Joined: Apr 17, 2007
Posts: 87
Thanks so much, it is wonderdful!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to group these JLabels?
 
Similar Threads
Why I cannot Move my JLabel after I add SetToolTipText()??
How to save configuration for my application??
How to draw straight line instead of curved line??
How to display Text String at the bottom of JLabel??
Can anybody help??