This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes Why I cannot Move my JLabel after I add SetToolTipText()?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Why I cannot Move my JLabel after I add SetToolTipText()??" Watch "Why I cannot Move my JLabel after I add SetToolTipText()??" New topic
Author

Why I cannot Move my JLabel after I add SetToolTipText()??

Michelle Wang
Ranch Hand

Joined: Apr 17, 2007
Posts: 87
Dear Friends:
I met a tough problem that I debugged for few days but cannot solve it.
after I add SetToolTipText I cannot Move my JLabel , what is wrong here??
see code below, here label1 cannot move.
If somebody can throw some lights, that will be wonderful,
so far no progress.

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
For some additional information you can check out the evaluation section of this:
Bug ID: 4413412 Mouse Events intercepted by Tooltip
Michelle Wang
Ranch Hand

Joined: Apr 17, 2007
Posts: 87
Thanks so much, it really works!! good weekends!!
Michelle Wang
Ranch Hand

Joined: Apr 17, 2007
Posts: 87
Thanks a lot for both super stars' great feed back.
I tried to cooperate my following code into your great code so that I can do:
[1]. setToolTipText
[2]. make JLabel DnD
and also
[3]. Make JLabel border resizeable, ie I can drag JLabel border and can resize it, I tried but fail several times, here I can DnD and resize, but cannot setToolTipText at same time, it fails.
It is Craig's great code before, see below:
Can gurus help some more??

Thanks


[ July 15, 2007: Message edited by: girl sunny ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
If you read the evaluation section of the bug report cited in reply 1 you will understand
why the addition of toolTipText calls on the child components consumes the MouseEvents which
should be reported in the mouse methods of the ComponentMover class. In the DnDJLabelsRx
class of reply 1 there is a MouseInputAdapter which overrides each mouse method found in the
ComponentMover nested class. This extra MouseInputAdapter is added to each child component
of the enclosing class (DnDJLabelsRx) for the purpose of receiving mouse input and re–
dispatching the (converted) MouseEvents to the parent/host class (DnDJLabelsRx).

So in your Resizing class you will need to do the same thing. Add a MouseInputAdapter to
each child component to receive/re–dispatch the MouseEvents that the ComponentMover class is
monitoring; there are four of these methods that this extra MouseInputAdapter must override
for this.
You might want to either change the class names or run this in a separate folder to avoid
name clashing and/or old class files. It seems to work okay as–is.
edit: fix typo and remove one sentence.
[ July 16, 2007: Message edited by: Craig Wood ]
Michelle Wang
Ranch Hand

Joined: Apr 17, 2007
Posts: 87
thanks so much for this so valuable advice
Michelle Wang
Ranch Hand

Joined: Apr 17, 2007
Posts: 87
Dear Sir:
Based on your wonderful code, I create another programs, both DnDJLabelsRx.java
DnDJLabelsRxOuter.java;

here they are very similiar, but DnDJLabelsRx.java calls DnDJLabelsRxOuter.java,

here, I can see all setToolTipText available,
but I met a problem:

I can move label2, label3, label4; but I cannot freely move label1 unless I press any child label in label1.

I hope
[1].when I click any child label in label1, this child label pressed will be dragged and dropped but its parent JPanel/JLabel=label1 not move, all other its siblings keep unchanged.

[2].when I click any blank space in label1 instead any of child labels in label1, I can only freely move/drag and drop whole label1(ie JPanel inside) but I cannot move any of its child labels

so far I cannot do that, can guru help??
Really thanks

1. main program:




2. called program:


[ July 18, 2007: Message edited by: girl sunny ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Most of the work for this was shown in DraggingAGroup in (reply 6 of) your previous thread
How to group these JLabels?
Michelle Wang
Ranch Hand

Joined: Apr 17, 2007
Posts: 87
Thanks a lot Craig, your excellent code gave me very valuable message,
My case is more general, for example,
Grandparent JPanel GParent has children JLabel Parent_A, Parent_B, Parent_C;
ParentA has children JLabels Child_A, Child_B, Child_C;
Child_A has GrandChild_A,GrandChild_B,GrandChild_C etc;
this family tree is unlimited;

How can I use a very simple way to pass dispatcher from bottom to any level of its ancestors??
ie, GrandChild_A can pass its dispatcher to not only Child_A, but also can pass its dispatcher to Parent_A, GrandChild_A etc so that in the top level or any levels above GrandChild_A, I can access and DnD the GrandChild_A and any other labels with easy, and I can DnD/move any JLabel in any level at my will after I setToolTipText for all JLabels. not like this case only two levels but so complicated.

Here my posted code(actually is Craig's great code) looks like more close to the requirements of my project.
Can guru help implement this more general idea??
Thanks
[ July 20, 2007: Message edited by: girl sunny ]
Michelle Wang
Ranch Hand

Joined: Apr 17, 2007
Posts: 87
my case is a little bit more complicated, it requires to pass/dispatch mouseMotionListener and mosueListener to not only its own parent, but its all possible ancestors, how to solve this more general problem??
really need help.
thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why I cannot Move my JLabel after I add SetToolTipText()??