[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?
|
hello Peter:
thank you so much
"Peter Goetz" <kingofbrain@xxxxxx> wrote in message
news:belmku$uob$1@xxxxxxxxxxxxxx
> 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
>
> >
> >
>