gpt4 book ai didi

java - 如何将工具提示包裹在属性 View 表条目中

转载 作者:行者123 更新时间:2023-12-02 09:49:22 24 4
gpt4 key购买 nike

我有一个带有 TableViewer 的默认 TabbedPropertySheetPage,它运行良好。属性 View 在窗口右侧打开,但表格单元格上的工具提示未显示表格单元格中的所有文本。

是否有可能包装并显示单元格数据的工具提示?

最佳答案

您可以尝试 JFace 页面中引用的以下代码片段。 JFace snippet link

请参阅Snippet037 - 精美的自定义工具提示。 (仅JFace 3.3版本支持)

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;

/**
* Explore JFace custom tooltips drawing.
*
*/

public class Snippet037FancyCustomTooltips {

private static class FancyToolTipSupport extends ColumnViewerToolTipSupport {

protected FancyToolTipSupport(ColumnViewer viewer, int style,
boolean manualActivation) {
super(viewer, style, manualActivation);
}

@Override
protected Composite createToolTipContentArea(Event event,
Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
GridLayout l = new GridLayout(1, false);
l.horizontalSpacing = 0;
l.marginWidth = 0;
l.marginHeight = 0;
l.verticalSpacing = 0;

comp.setLayout(l);
Browser browser = new Browser(comp, SWT.BORDER);
browser.setText(getText(event));
browser.setLayoutData(new GridData(200, 150));

return comp;
}

@Override
public boolean isHideOnMouseDown() {
return false;
}

public static final void enableFor(ColumnViewer viewer, int style) {
new FancyToolTipSupport(viewer, style, false);
}
}

/**
* @param args
*/
public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

TableViewer v = new TableViewer(shell, SWT.FULL_SELECTION);
v.getTable().setLinesVisible(true);
v.getTable().setHeaderVisible(true);
v.setContentProvider(ArrayContentProvider.getInstance());
FancyToolTipSupport.enableFor(v, ToolTip.NO_RECREATE);

CellLabelProvider labelProvider = new CellLabelProvider() {

@Override
public String getToolTipText(Object element) {
return "<html><body>Tooltip ("
+ element
+ ")<br /><a href='http://www.bestsolution.at' target='_NEW'>www.bestsolution.at</a></body></html>";
}

@Override
public Point getToolTipShift(Object object) {
return new Point(5, 5);
}

@Override
public int getToolTipDisplayDelayTime(Object object) {
return 2000;
}

@Override
public int getToolTipTimeDisplayed(Object object) {
return 5000;
}

@Override
public void update(ViewerCell cell) {
cell.setText(cell.getElement().toString());
}
};

TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
column.setLabelProvider(labelProvider);
column.getColumn().setText("Column 1");
column.getColumn().setWidth(100);
String[] values = new String[] { "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten" };
v.setInput(values);

shell.setSize(200, 200);
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}

Snippet output

关于java - 如何将工具提示包裹在属性 View 表条目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56421798/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com