Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Tooltips for disabled Buttons
Tooltips for disabled Buttons [message #733652] Wed, 05 October 2011 10:04 Go to next message
T. Wilhelm is currently offline T. WilhelmFriend
Messages: 8
Registered: December 2010
Junior Member
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 Sad Does anyone have a good workaround?

Thanks alot
Thomas
Re: Tooltips for disabled Buttons [message #734399 is a reply to message #733652] Fri, 07 October 2011 15:40 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
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 13:25 Go to previous message
Andrzej Witecki is currently offline Andrzej WiteckiFriend
Messages: 2
Registered: November 2015
Junior Member
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:"); 
Previous Topic:Event.{x,y} are zero
Next Topic:Tabitem dispose in Linux - possible bug
Goto Forum:
  


Current Time: Tue Mar 19 04:37:30 GMT 2024

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

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

Back to the top