final Text text = new Text(top, SWT.SINGLE | SWT.LEAD | SWT.BORDER); text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); text.setText("");
final Color bgColor = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_RED); final Color fgColor = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_BLACK);
final AtomicReference<Integer> x = new AtomicReference<Integer>(); final AtomicReference<Integer> y = new AtomicReference<Integer>();
ToolTipText 背景颜色设置,边框设置?怎么弄呢? 就是在给控件setToolTipText()时,怎么改变背景颜色,边框设置呢?
比如说:jLabel1.setToolTipText("asd"),怎么改变asd的背景色,边框设置。?麻烦给个例子说明哈呢。。谢谢先
比如说:jLabel1.setToolTipText("asd"),怎么改变asd的背景色,边框设置。? 麻烦给个例子说明哈呢。。谢谢先
public void createPartControl(Composite parent) {
final Composite top = new Composite(parent, SWT.NONE);
GridLayout topLayout = new GridLayout(2, false);
top.setLayout(topLayout);
Label label = new Label(top, SWT.NONE);
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,false));
label.setText("Name:");
final Text text = new Text(top, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
text.setText("");
final Color bgColor = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_RED);
final Color fgColor = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_BLACK);
final AtomicReference<Integer> x = new AtomicReference<Integer>();
final AtomicReference<Integer> y = new AtomicReference<Integer>();
text.addMouseTrackListener(new MouseTrackAdapter(){ public void mouseHover(MouseEvent e) {
x.set(e.x);
y.set(e.y);
text.redraw();
}
});
text.addPaintListener(new PaintListener(){ public void paintControl(PaintEvent e) {
GC gc = e.gc;
if(x.get() != null && y.get() != null){
Rectangle rect = new Rectangle(x.get(),y.get(),100,20);
gc.setBackground(bgColor);
gc.setForeground(fgColor);
gc.fillRectangle(rect);
gc.drawText("Hello, it works!", rect.x, rect.y);
}
}
});
}
如:setToolTipText("<html><font color="#123456">nihao</font></html>");
class MyButton extends JButton {
@Override
public JToolTip createToolTip() {
JToolTip jt = super.createToolTip();
jt.setBackground(Color.WHITE);
jt.updateUI();
return jt;
}
}
例子中将toolTipText的背景变成白色的了。
用MyButton声明你的实例,就行了