On windows operating systems button.setBackGround
doesn't work directly. A small snippet of code can help. Override the paint event of button as shown below:-
-----obj is button name in below snippet------------
obj.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent arg0) {
// TODO Auto-generated method stub
obj.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
org.eclipse.swt.graphics.Pattern pattern;
pattern = new org.eclipse.swt.graphics.Pattern(arg0.gc.getDevice(), 0,0,0,100, arg0.gc.getDevice().getSystemColor(SWT.COLOR_GRAY),230, arg0.gc.getDevice().getSystemColor(SWT.COLOR_BLACK),230);
arg0.gc.setBackgroundPattern(pattern);
arg0.gc.fillGradientRectangle(0, 0, obj.getBounds().width, obj.getBounds().height, true);
}
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…