Re: Moving objects on GlassPane ignores setLocation()
In article
<450b0e5e-0f54-4e7a-b71d-e93552856e27@a1g2000hsb.googlegroups.com>,
Icarus <kristian.heidmann@web.de> wrote:
[...]
Below is some sample code replicating the problem. Move the mouse in
the program window. Then use the mouse button, but don't move the
mouse. You will see the picture enter the window at the top, centered
vertically, even though the program sets the location to that of the
mouse cursor. If you now move the mouse, the program behaves correctly
again.
Do you have any idea how to correct this?
The top center placement is a feature of the (default) FlowLayout in the
glassPane. Change it too a GridLayout to see a different effect; set it
to null to preclude the effect.
[...]
// Create a new GlassPane
JPanel glasspane = new JPanel(new GridLayout(1, 1));
[...]
In the listener, set the point to something on MOUSE_EXITED to avoid an
NPE. Click on the label and drag the frame around to see the label move
relative to the frame:
// In case of a MouseEvent, move the object that's
// currently on the GlassPane to the location of the event
Point point;
if (me.getID() == MouseEvent.MOUSE_EXITED
&& me.getComponent() == PickUpAndDrop2.instance) {
point = new Point(0, 0);
} else {
I think you need a different transformation here. Also, this code needs
to distinguish between events from the label and the the underlying
frame:
MouseEvent converted =
SwingUtilities.convertMouseEvent(
me.getComponent(), me,
PickUpAndDrop2.instance.getGlassPane());
point = converted.getPoint();
}
PickUpAndDrop2.instance.moveLabel(point);
}
Have you looked at this?
<http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html
#glasspane>
Sorry to be vague, but this feature is new to me.
[...]
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews