Re: How can I "glue" JDialog to an owning JFrame ?



bobjan wrote:
I have a non-modal JDialog with a JFrame as an owner.
On a mouse right-click the dialog  becomes visible at the mouse
position. And it works fine. But when I start dragging JFrame , the
JDialog remains on the same screen position. Is there a way to "glue"
the dialog to the frame ?

JFrame has addComponentListener and addMouseMotionListener methods, inherited from Component. So you might want:
yourFrame.addComponentListener(new ComponentAdapter()
{
public void componentMoved(...) { ... }
});
or
yourFrame.addMouseMotionListener(new MouseAdapter()
{
public void mouseDragged(...) { ... }
});


But another question:
Why do you want to move the dialog at all, when the user moves the frame? I think that would surprise your user, and hence would contradict to the "principle of least astonishment" <http://www.google.de/search?q=%22principle+of+least+astonishment%22>
And consider a desperate user's question "I just moved the dialog totally off the screen. How can I close it now?" ;-)


--
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

.