【发布时间】:2015-03-10 15:11:10
【问题描述】:
我想在 Java SWT 中为 StyledText 设置工具提示。这个想法是显示鼠标点击的文本信息。到目前为止,我只能在工具提示中显示文本,但我希望整个工具提示是一个图像,它是使用 SWT 中的绘图方法绘制的,以显示信息中的一些结构。似乎 Tooltip 无法处理,所以任何人都可以建议我如何做到这一点,或者我可以使用哪个小部件来实现它?
编辑:如何设置createToolTipContentArea 返回的合成的大小?
protected Composite createToolTipContentArea(Event event, Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.addPaintListener(new SPPaintListener());
composite.setSize(680, 600);
return composite;
}
private class SPPaintListener implements PaintListener {
public void paintControl(PaintEvent e) {
drawLyrics(e);
e.gc.dispose();
}
}
private void drawLyrics(PaintEvent e) {
e.gc.setAntialias(SWT.ON);
Font font = new Font(e.display, "Purisa", 10, SWT.NORMAL);
Color color = new Color(e.display, 25, 25, 25);
e.gc.setForeground(color);
e.gc.setFont(font);
e.gc.drawText("em so transitory", 20, 30);
e.gc.drawText("em so transitory", 180, 30);
e.gc.drawText("Theermanent one", 20, 60);
e.gc.drawText("Theermanent one", 180, 60);
e.gc.drawLine(10, 30, 15, 30);
font.dispose();
}
就像说的那样,我需要一些复合材料上的画,但它们不会完全显示出来。
【问题讨论】:
-
如果您不局限于 SWT,JFace
ToolTip类可以做到这一点。