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