Topic: 扩展SWT的button遇到的问题?

  Print this page

1.扩展SWT的button遇到的问题? Copy to clipboard
Posted by: funpig
Posted on: 2004-07-26 13:03

我自己扩展了swt的button,想在鼠标移动到button上时改变button的背景色,可是button却没有重绘,有人知道怎么做吗?我的代码如下:

public class ZButton extends Button{
private Color background = null;
private Color foreground = null;
private Color beginColor = null;
private Color endColor = null;

public ZButton(Composite arg0,int arg1)
{
super(arg0,arg1);
if(background == null)
{
background = new Color(arg0.getDisplay(), 125, 125, 125);
foreground = new Color(arg0.getDisplay(), 255, 255, 255);
//beginColor = new Color(arg0.getDisplay(), 115,140,165);
beginColor = new Color(arg0.getDisplay(), 255,0,0);
endColor = new Color(arg0.getDisplay(), 185,200,210);
}
setBackground(beginColor);
//setForeground(beginColor);

addMouseTrackListener(new MouseTrackListener() {
public void mouseHover(MouseEvent e) {
}

public void mouseExit(MouseEvent e) {
setBackground(background);
redraw();
System.out.println("mouse exit button");
}

public void mouseEnter(MouseEvent e) {
setForeground(beginColor);
redraw();
System.out.println("mouse enter button");
}
});

addDisposeListener(new DisposeListener(){
public void widgetDisposed(DisposeEvent arg0) {
    background.dispose();
    foreground.dispose();
    beginColor.dispose();
    endColor.dispose();
  }
});
}
}

2.Re:扩展SWT的button遇到的问题? [Re: funpig] Copy to clipboard
Posted by: yaobifeng
Posted on: 2004-07-27 17:12

调用redraw()方法刷新或者自己在paint事件里处理

3.Re:扩展SWT的button遇到的问题? [Re: funpig] Copy to clipboard
Posted by: funpig
Posted on: 2004-07-27 17:35

我有调用啊,但是没效果

public void mouseEnter(MouseEvent e) {
setForeground(beginColor);
redraw();
System.out.println("mouse enter button");
}

4.Re:扩展SWT的button遇到的问题? [Re: funpig] Copy to clipboard
Posted by: yipsilon
Posted on: 2004-08-13 12:12

SWT的Button好像不让子类继承哦....

5.Re:扩展SWT的button遇到的问题? [Re: funpig] Copy to clipboard
Posted by: kite
Posted on: 2004-08-16 17:21

SWT中的GUI组件不能继承,如果你要这种效果,你应该用Listener或者是用一个Composite组合Button,或是自己画。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923