0
我试图实现一种方法,如果用户没有输入任何内容,则会在文本等控件周围绘制红色边框。我使用eclipse swt。 我的方法看起来像这样:在错误的文字周围绘制红色边框
protected void drawRedBorder(Control cont){
final Control control = cont;
cont.getParent().addPaintListener(new PaintListener(){
public void paintControl(PaintEvent e){
GC gc = e.gc;
Color red = new Color(null, 255, 0 ,0);
gc.setBackground(red);
Rectangle rect = control.getBounds();
Rectangle rect1 = new Rectangle(rect.x - 2, rect.y - 2,
rect.width + 4, rect.height + 4);
gc.setLineStyle(SWT.LINE_SOLID);
gc.fillRectangle(rect1);
}
});
}
它工作正常,当我把它创建带有文本字段的对话框时。然而,它不起作用,当我在CheckInput()方法中调用它时,它会检查用户是否输入了某个东西。
我试图通过调用redraw()或update()来解决问题,但没有任何工作。任何线索我怎么能解决这个问题?
你尝试'updateUI()'? – Sam
我可以在哪里调用此方法? – antumin
调用'drawRedBorder'方法后。 – Sam