我将JAVA SWT用于JAVA应用程序的GUI。
现在,我已设置一个复选框为禁用状态,但我想显示相同的工具提示。
这可能吗?
我的代码是:
myCheckbox.setSelection(false);
myCheckbox.setEnabled(false);
myCheckbox.setToolTipText("Tooltip message");
Run Code Online (Sandbox Code Playgroud)
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");
myCheckbox.setEnabled(false);
// assign the same tooltip to the encapsulating composite
myCheckbox.getParent().setToolTipText(myCheckbox.getToolTipText());
shell.setSize(200, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
953 次 |
| 最近记录: |