关于org.eclipse.swt.widgets.Decorations 控件的问题

FF1280 2011-03-11 04:04:14
请教一下关于org.eclipse.swt.widgets.Decorations 控件的问题
点击一个button,然后new 一个Decorations,显示在Canvas上。
但是Decorations不显示。
使用了canvas.redraw()和decorations.redraw()方法也不显示。
请问怎么刷新显示?


代码:
package first_rcp.test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Decorations;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class TestDecorations {
public static void main(String args[]) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Decorations One");
shell.setLayout(new GridLayout(1,true));
final Canvas canvas = new Canvas(shell, SWT.NONE);

canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
Decorations d = new Decorations(canvas, SWT.CLOSE | SWT.RESIZE );
d.setLayoutData(new GridData(GridData.FILL_BOTH));
d.setLayout(new FillLayout());
d.setText("TestDecorations");
Label l = new Label(d, SWT.CENTER);
l.setText("SWT.TOOL");
d.setLocation(50, 50);
d.pack();

Button button = new Button(canvas, SWT.PUSH);
button.setText("button");
button.setBounds(20, 20, 50, 20);
System.out.println("button 之前控件数: " + canvas.getChildren().length);
button.addMouseListener(new MouseListener() {
@Override
public void mouseDown(MouseEvent e) {
System.out.println("Button down");

Decorations d1 = new Decorations(canvas, SWT.CLOSE | SWT.RESIZE | SWT.ON_TOP);
d1.setLayoutData(new GridData(GridData.FILL_BOTH));
d1.setLayout(new FillLayout());
d1.setText("Decorations d1");
Label l1 = new Label(d1, SWT.CENTER);
l1.setText("Decorations d1 Label");
d1.setLocation(80, 80);
d1.pack();

// Button button = new Button(canvas, SWT.PUSH);
// button.setText("点击");
// button.setBounds(70, 70, 50, 20);

// d1.redraw();
// canvas.redraw();

System.out.println("button 之后控件数: " + canvas.getChildren().length);
System.out.println("button后 "+ d1.getText() + " X: "+ d1.getLocation().x + " Y: " + d1.getLocation().y);
System.out.println();
}
@Override
public void mouseUp(MouseEvent e) {}
@Override
public void mouseDoubleClick(MouseEvent arg0) {}
});

shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
...全文
151 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
FF1280 2011-03-12
  • 打赏
  • 举报
回复
问题已经解决了:
需要设置:
d1.setVisible(true);

58,452

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧