Sandeep T D S Sandeep T D S -4 years ago 160
Java Question

Tooltip is not visible for a disabled Control in JAVA SWT

I am using JAVA SWT for the GUI of my JAVA application.

Now i have set a checkbox to be disabled, but i want to show the tooltip for the same.

Is this possible?

My code is:

myCheckbox.setToolTipText("Tooltip message");

Answer Source

As pointed out by greg-449 in his answer, it is not possible.

But if you really want to, you could workaround this limitation by encapsulating your checkbox in a Composite with the same tooltip text.

This method was proposed by Andrzej Witecki in this Eclipse forum topic.

An example:

public static void main(String[] args) {

    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());

    Composite c = new Composite(shell, SWT.NONE);
    c.setLayoutData(new GridData());  // default values so it doesn't grab excess space
    c.setLayout(new FillLayout());

    Button myCheckbox = new Button(c, SWT.CHECK);
    myCheckbox.setText("Checkbox text");
    myCheckbox.setToolTipText("Tooltip message");

    // assign the same tooltip to the encapsulating composite

    shell.setSize(200, 200);;

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download