我正在制作星云网格表。我返回到getToolTipText()
方法的字符串不适合多行,同时它显示在单行中。我使用下面的代码来实现多行工具提示。但我还是得到了单行字符串
ColumnViewerToolTipSupport toolTipSupport = new ColumnViewerToolTipSupport(col.getViewer(), SWT.NONE, false) {
@Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
comp.setLayout(new FillLayout());
comp.setBounds(0, 0, 250, 250);
Text b = new Text(comp, SWT.LEFT);
b.setText(getText(event));
Activator.log("Text: " + getText(event), Status.INFO);
b.setBackground(new Color(null, 255, 0, 0));
b.setSize(250, 250);
// b.addSelectionListener(new SelectionAdapter() {
// @Override
// public void widgetSelected(SelectionEvent e) {
// hide();
// MessageBox box = new MessageBox(.getShell(),SWT.ICON_INFORMATION);
// box.setMessage("Hello World!");
// box.setText("Hello World");
// box.open();
// }
// });
return comp;
}
};
如果需要多行支持,则需要在Text
控件上指定SWT.MULTI
样式。
如果你想换行,也要指定SWT.WRAP
样式。
:
Text b = new Text(comp, SWT.LEFT | SWT.MULTI | SWT.WRAP);