<p>有需求如下:</p>
<p>在提交数据时,如果SWT文本框数值为空,则改变文本框的边框,以提醒用户.</p>
<p>实现思路:通过绘制GC实现.</p>
<p>代码如下:</p>
<pre name="code" class="java">Text text = new Text(new Shell(), SWT.NONE);
// 在指定情况下重写监听实现.如数据为空时..
if (text.getText().trim().equals("")) {
text.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
GC gc = e.gc;
gc.setForeground(ImageUtil.txtBorderColor);
// 在文本框内实现加一条底线
// gc.drawRectangle(e.x - 1, e.y - 1, e.width + 1,
// e.height);
// 修改文本框整个边框颜色
gc.drawRectangle(e.x, e.y, e.width - 1, e.height - 1); gc = null;
}
});
}</pre>
<p>?</p>
<p>?</p>
<p>?</p>
<p>-------------------------工作积累 尹当?</p>
<p>在提交数据时,如果SWT文本框数值为空,则改变文本框的边框,以提醒用户.</p>
<p>实现思路:通过绘制GC实现.</p>
<p>代码如下:</p>
<pre name="code" class="java">Text text = new Text(new Shell(), SWT.NONE);
// 在指定情况下重写监听实现.如数据为空时..
if (text.getText().trim().equals("")) {
text.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
GC gc = e.gc;
gc.setForeground(ImageUtil.txtBorderColor);
// 在文本框内实现加一条底线
// gc.drawRectangle(e.x - 1, e.y - 1, e.width + 1,
// e.height);
// 修改文本框整个边框颜色
gc.drawRectangle(e.x, e.y, e.width - 1, e.height - 1); gc = null;
}
});
}</pre>
<p>?</p>
<p>?</p>
<p>?</p>
<p>-------------------------工作积累 尹当?</p>