Re: Moving objects on GlassPane ignores setLocation()
In article
<f364bcce-22d7-45a4-9764-4795499632ae@y38g2000hsy.googlegroups.com>,
Icarus <kristian.heidmann@web.de> wrote:
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.
Is there a way to avoid/ciercumvent this effect altogether? I dotry to
move the component to the right location immediately after placement,
but the change is ignored or at least not drawn. Although it's the
same command that gets triggered by the MouseMotionEvents.
I think the problem is that it's the same label on both panes: it's
alternately being redrawn on the glassPane and repainted on the frame's
contentPane.
Have you looked at this?
<http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html
#glasspane>
I did look at it, but somehow the old image didn't get deleted when it
was moved to a new location. And at this point, changing the behaviour
to overriding paintComponent won't do anymore, as it would break my
structure.
I don't see a way around it: the same component can't be in two
locations at once.
Sorry to be vague, but this feature is new to me.
As it's with me. -_- Nonetheless, do you (or someone else) have any
ideas especially on the problem with the wrong starting location?
Start with the GlassPaneDemo and request repaint for drag and pressed:
public void mouseDragged(MouseEvent e) {
redispatchMouseEvent(e, true);
}
public void mousePressed(MouseEvent e) {
redispatchMouseEvent(e, true);
}
Then tracking works perfectly:
protected void paintComponent(Graphics g) {
if (point != null) {
g.setColor(Color.red);
g.drawRect(point.x, point.y, 60, 20);
}
}
Of course, you want to drag a label, not just an outline. A LayeredPane
might work:
<http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.h
tml?
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews