[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: how to show text message under the mouse?
|
- From: Peter Goetz <kingofbrain@xxxxxx>
- Date: Fri, 11 Jul 2003 08:46:25 +0200
- Newsgroups: eclipse.platform.swt
- Organization: EclipseCorner
- User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624
Daniel Mark wrote:
hello all:
Hi Daniel,
I want to do a simple draw tool using java.
whenever the user moves the mouse, I need to
show current coordinate as (x, y) right beside the mouse
pointer.
You could add a Tooltip to the widget you want to give the coordinates of.
Also you have to add a MouseMoveListener to the widget. Every time the mouse
moves, the text for the tooltip gets updated.
I have coded this little example for you:
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class XYCoordinates
{
public static void main(String[] args)
{
Display display = new Display ();
Shell shell = new Shell (display);
Composite comp = new Composite(shell, SWT.NONE);
comp.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
comp.addMouseMoveListener(new MouseMoveListener()
{
public void mouseMove(MouseEvent e)
{
((Composite) e.getSource()).setToolTipText(
"" + e.x + "," + e.y);
}
});
shell.setSize(400, 400);
shell.setLayout(new FillLayout());
shell.open ();
while (!shell.isDisposed ())
{
if (!display.readAndDispatch ())
{
display.sleep ();
}
}
display.dispose ();
}
}
how can I do?
thank you
-Daniel
HTH, Peter