JavaSWT:在工具提示中显示绘画
我想在JavaSWT中为StyledText设置工具提示。其思想是在鼠标单击的位置显示文本的信息。到目前为止,我只能在工具提示中显示文本,但我希望整个工具提示是一个图像,它是使用SWT中的绘图方法绘制的,以显示信息中的某些结构。工具提示似乎不能解决这个问题,所以有人能给我建议怎么做,或者用哪个小部件来实现吗 编辑:如何设置JavaSWT:在工具提示中显示绘画,java,image,swt,tooltip,Java,Image,Swt,Tooltip,我想在JavaSWT中为StyledText设置工具提示。其思想是在鼠标单击的位置显示文本的信息。到目前为止,我只能在工具提示中显示文本,但我希望整个工具提示是一个图像,它是使用SWT中的绘图方法绘制的,以显示信息中的某些结构。工具提示似乎不能解决这个问题,所以有人能给我建议怎么做,或者用哪个小部件来实现吗 编辑:如何设置createToolTipContentArea返回的组合的大小 protected Composite createToolTipContentArea(Event even
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();
}
如前所述,我需要在合成图上绘制一些图片,但它们不会完全显示。您可以使用从
org.eclipse.jface.window.ToolTip
派生的类在工具提示中绘制任何您喜欢的内容
public class MyToolTip extends ToolTip
{
public MyToolTip(Control control)
{
super(control, NO_RECREATE, false);
}
@Override
protected Composite createToolTipContentArea(final Event event, final Composite parent)
{
// TODO add your controls here
}
}
用于:
new MyToolTip(control);
其中control
是应该具有工具提示的控件
我已经展示了最简单的表单,其中工具提示区域对于整个控件是相同的。您还可以重写gettooltipera
方法,根据控件中的位置更改工具提示
对于图像,createToolTopArea可能如下所示:
@Override
protected Composite createToolTipContentArea(final Event event, final Composite parent)
{
Composite body = new Composite(parent, SWT.NONE);
body.setLayout(new GridLayout());
Label label = new Label(body, SWT.LEAD);
Image image = ... your image
label.setImage(image);
return body;
}
JFace
工具提示
类可以做到这一点,如果你不局限于SWT。嗨,格雷格,谢谢你的回答,这应该符合我的要求,但只有一个问题:我如何设置工具提示的大小?我试过了,看起来大小是根据它显示的文本自动计算出来的。但是我需要显示一个带有绘图的合成图,并且我只能显示其中的一部分。我添加了一个示例,示例根据我使用的代码改编。是的,我已经使用过它,但我仍然无法设置合成图的大小。看看我的最新帖子。我从来没有试过这样的东西。您可能需要主合成的子画布。使用主组合上的GridLayout,可以将GridData用于子组合的LayoutData,并可以指定widthHint和heightHint值。