Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Wrong location of ToolTip for some circumstances
Wrong location of ToolTip for some circumstances [message #497661] Fri, 13 November 2009 10:32 Go to next message
Andrey Kononenko is currently offline Andrey KononenkoFriend
Messages: 11
Registered: July 2009
Junior Member
Hi!

I've faced a strange and annoying problem with ToolTip in Windows XP. If I set a location for the tooltip and a tooltip message could not be shown for the location (because location too close to border of visible area) the tooltip jumps up to the top of shell. I've tried to predict the situation and adjust the location, but it is not possible for all cases (e.g. long or multyline strings). I would grateful for any reasonable solution or any suggestion how to avoid the jumping and wrong location.

To see the issue you can use an attached snippet (move the shell to the bottom of display and hover over the text at the bottom of the shell). Result: tooltip bar jumps to the top of the sell.

Thank you in advance for any help.

/Andrey


package com.maconomy.lib.widget.examples;

/*
* Tool Tips example snippet:
*
* For a list of all SWT example snippets see
* http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/dev.html#snippets
*/
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolTip;

public class Snippet125 {

public static void main(final String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new RowLayout());
for (int i = 0; i < 100; i++) {
final StyledText text = new StyledText(shell, SWT.NONE);
final ToolTip toolTip = new ToolTip(shell, SWT.NONE);
final Listener listener = new Listener() {
public void handleEvent(final Event event) {
final Point toolTipLocation = text.getLocation();
final Point commonToolTipLocation = shell.toDisplay(toolTipLocation);
toolTipLocation.y = commonToolTipLocation.y;
toolTipLocation.x = commonToolTipLocation.x;
toolTip.setMessage("Multy line message part 1 \n Multy line message part 2 \n Multy line message part 1 ");
toolTip.setLocation(toolTipLocation);
toolTip.setVisible(true);
}
};
text.addListener(SWT.MouseHover, listener);
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}
Re: Wrong location of ToolTip for some circumstances [message #497991 is a reply to message #497661] Fri, 13 November 2009 15:32 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Andrey,

I think the only way is to not set the tooltip's y too low. Changing your
MouseHover listener to the one below works for me on Windows 2000, and
should work elsewhere, though you may wish to increase the value of
ARBITRARILY_CHOSEN_TOOLTIP_TRIM_HEIGHT to be safer.

public void handleEvent(final Event event) {
String string = "Multy line message part 1 \n Multy line message part 2 \n
Multy line message part 1 ";

/*
* unfortunately ToolTip does not implement computeSize(), so approximate
* its height by measuring the string and add some pixels for ToolTip trim
*/
GC gc = new GC(display);
int textHeight = gc.textExtent(string).y;
gc.dispose();
int ARBITRARILY_CHOSEN_TOOLTIP_TRIM_HEIGHT = 6;
int monitorHeight = shell.getMonitor().getClientArea().height;
int maxY = monitorHeight - (textHeight +
ARBITRARILY_CHOSEN_TOOLTIP_TRIM_HEIGHT);

final Point toolTipLocation = text.getLocation();
final Point commonToolTipLocation = shell.toDisplay(toolTipLocation);
toolTipLocation.x = commonToolTipLocation.x;
toolTipLocation.y = Math.min (maxY, commonToolTipLocation.y);
toolTip.setMessage(string);
toolTip.setLocation(toolTipLocation);
toolTip.setVisible(true);
}

Grant


"Andrey Kononenko" <and.konon@gmail.com> wrote in message
news:hdjcj9$5eo$1@build.eclipse.org...
> Hi!
>
> I've faced a strange and annoying problem with ToolTip in Windows XP. If I
set a location for the tooltip and a tooltip message could not be shown for
the location (because location too close to border of visible area) the
tooltip jumps up to the top of shell. I've tried to predict the situation
and adjust the location, but it is not possible for all cases (e.g. long or
multyline strings). I would grateful for any reasonable solution or any
suggestion how to avoid the jumping and wrong location.
>
> To see the issue you can use an attached snippet (move the shell to the
bottom of display and hover over the text at the bottom of the shell).
Result: tooltip bar jumps to the top of the sell.
>
> Thank you in advance for any help.
>
> /Andrey
>
>
> package com.maconomy.lib.widget.examples;
>
> /*
> * Tool Tips example snippet:
> *
> * For a list of all SWT example snippets see
> *
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/dev.html#snippets
> */
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.StyledText;
> import org.eclipse.swt.graphics.Point;
> import org.eclipse.swt.layout.RowLayout;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Event;
> import org.eclipse.swt.widgets.Listener;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.ToolTip;
>
> public class Snippet125 {
>
> public static void main(final String[] args) {
> final Display display = new Display();
> final Shell shell = new Shell(display);
> shell.setLayout(new RowLayout());
> for (int i = 0; i < 100; i++) {
> final StyledText text = new StyledText(shell, SWT.NONE);
> final ToolTip toolTip = new ToolTip(shell, SWT.NONE);
> final Listener listener = new Listener() {
> public void handleEvent(final Event event) {
> final Point toolTipLocation = text.getLocation();
> final Point commonToolTipLocation =
shell.toDisplay(toolTipLocation);
> toolTipLocation.y = commonToolTipLocation.y;
> toolTipLocation.x = commonToolTipLocation.x;
> toolTip.setMessage("Multy line message part 1 \n Multy line
message part 2 \n Multy line message part 1 ");
> toolTip.setLocation(toolTipLocation);
> toolTip.setVisible(true);
> }
> };
> text.addListener(SWT.MouseHover, listener);
> }
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
> }
>
Previous Topic:listener for enable/disable events?
Next Topic:Key bindings in custom widgets
Goto Forum:
  


Current Time: Tue Apr 23 10:26:10 GMT 2024

Powered by FUDForum. Page generated in 0.04159 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top