|
Re: Tooltips for disabled Buttons [message #734399 is a reply to message #733652] |
Fri, 07 October 2011 11:40   |
Eclipse User |
|
|
|
Hi Thomas,
(verified on win32) The following snippet demonstrates getting a
MouseHover event. From this you should be able to show a custom tooltip
(either a ToolTip instance or an emulated tooltip like in
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java
).
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
Composite composite = new Composite(shell, SWT.NONE);
composite.setBounds(10,10,90,50);
Button button = new Button(composite, SWT.PUSH);
button.setBounds(0,0,90,50);
button.setText("button");
composite.addListener(SWT.MouseHover, new Listener() {
public void handleEvent(Event event) {
System.out.println("called");
// show a custom tooltip here
}
});
button.setEnabled(false);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
Grant
On 10/5/2011 6:04 AM, T. Wilhelm wrote:
> Hi all,
>
> i want to show a tooltip for a disabled button (because i want to
> display why it´s disabled), is there any solution? I already searched in
> this forum, but the answer was that it is the expected behaviour on
> windows that disabled buttons cannot show tooltips :( Does anyone have a
> good workaround?
>
> Thanks alot
> Thomas
|
|
|
Re: Tooltips for disabled Buttons [message #1715238 is a reply to message #734399] |
Fri, 20 November 2015 08:25  |
Eclipse User |
|
|
|
Hi,
I know it's been a long time since you asked your question but people may still find my answer useful as it is simpler than the previous one and kinda generic for every "disabled control" problem.
You may always encapsulate your button within a marginless Composite and set your tooltip on it when you're disabling your button. Therefore "SWT event handler" (I don't know how to name it properly TBH) will traverse through the SWT control hierarchy (starting from the button and moving onto Composite) till it find non-disabled control and will use it's tooltip.
E.g.
final Composite buttonContainer = new Composite(mainContainer, SWT.NONE);
buttonContainer.setLayout(new FillLayout());
GridDataFactory.fillDefaults().applyTo(buttonContainer);
final Button button = new Button(buttonContainer, SWT.NONE);
button.setToolTipText("Button enabled tooltip");
return button;
(...)
// setting empty String is not necessary but IMHO it's safer as I don't know the SWT behaviour on every platform
button.setEnabled(isAddButtonEnabled);
button.setToolTipText(isAddButtonEnabled ? "Button enabled text" : "");
button.getParent().setToolTipText(isAddButtonEnabled ? "" : "Button disabled text:");
|
|
|
Powered by
FUDForum. Page generated in 0.04364 seconds