swt与awt/swing互嵌
来源:互联网 发布:淘宝店铺级别分类 编辑:程序博客网 时间:2024/05/16 11:06
SWT中嵌入awt/swing控件:
public static void main(String[] args) ...{
final Display display = new Display();
final Shell shell = new Shell(display,SWT.EMBEDDED);
Frame frame = SWT_AWT.new_Frame(shell);
frame.setLayout(new BorderLayout());
frame.setBackground(Color.blue);
frame.add(new JLabel("I'm swing label."),BorderLayout.NORTH);
JButton btnClose=new JButton("close");
btnClose.addActionListener(new ActionListener()...{
public void actionPerformed(ActionEvent e) ...{
display.syncExec(new Runnable()...{
public void run()...{
shell.close();
}
});
}
});
frame.add(btnClose,BorderLayout.SOUTH);
Panel panel = new Panel();
panel.setBackground(Color.orange);
frame.add(panel,BorderLayout.CENTER);
shell.setSize(400, 300);
shell.open();
while (!shell.isDisposed()) ...{
while (!display.readAndDispatch()) ...{
display.sleep();
}
}
display.dispose();
}
final Display display = new Display();
final Shell shell = new Shell(display,SWT.EMBEDDED);
Frame frame = SWT_AWT.new_Frame(shell);
frame.setLayout(new BorderLayout());
frame.setBackground(Color.blue);
frame.add(new JLabel("I'm swing label."),BorderLayout.NORTH);
JButton btnClose=new JButton("close");
btnClose.addActionListener(new ActionListener()...{
public void actionPerformed(ActionEvent e) ...{
display.syncExec(new Runnable()...{
public void run()...{
shell.close();
}
});
}
});
frame.add(btnClose,BorderLayout.SOUTH);
Panel panel = new Panel();
panel.setBackground(Color.orange);
frame.add(panel,BorderLayout.CENTER);
shell.setSize(400, 300);
shell.open();
while (!shell.isDisposed()) ...{
while (!display.readAndDispatch()) ...{
display.sleep();
}
}
display.dispose();
}
Eclipse视图效果:
public void createPartControl(Composite parent) ...{
Composite p=new Composite(parent,SWT.EMBEDDED);
Frame frame = SWT_AWT.new_Frame(p);
frame.setLayout(new BorderLayout());
frame.setBackground(Color.blue);
frame.add(new JLabel("I'm swing label."),BorderLayout.NORTH);
JButton btnClose=new JButton("close");
frame.add(btnClose,BorderLayout.SOUTH);
Panel panel = new Panel();
panel.setBackground(Color.orange);
frame.add(panel,BorderLayout.CENTER);
}
Composite p=new Composite(parent,SWT.EMBEDDED);
Frame frame = SWT_AWT.new_Frame(p);
frame.setLayout(new BorderLayout());
frame.setBackground(Color.blue);
frame.add(new JLabel("I'm swing label."),BorderLayout.NORTH);
JButton btnClose=new JButton("close");
frame.add(btnClose,BorderLayout.SOUTH);
Panel panel = new Panel();
panel.setBackground(Color.orange);
frame.add(panel,BorderLayout.CENTER);
}
swing/awt中使用swt
public static void main(String[] args) ...{
final JFrame frame = new JFrame();
Canvas canvas = new Canvas();
frame.getContentPane().add(canvas,BorderLayout.CENTER);
frame.setVisible(true);
Display display = new Display();
final Shell shell = SWT_AWT.new_Shell(display,canvas);
shell.setLayout(new FillLayout());
Button button = new Button(shell,SWT.PUSH);
button.setText("SWT Button");
button.addSelectionListener(new SelectionListener()...{
public void widgetDefaultSelected(SelectionEvent e) ...{
}
public void widgetSelected(SelectionEvent e) ...{
SwingUtilities.invokeLater(new Runnable()...{
public void run()...{
frame.dispose();
}
});
}
});
frame.setSize(400,300);
while (!shell.isDisposed()) ...{
if (!display.readAndDispatch())...{
display.sleep ();
}
}
display.dispose();
}
final JFrame frame = new JFrame();
Canvas canvas = new Canvas();
frame.getContentPane().add(canvas,BorderLayout.CENTER);
frame.setVisible(true);
Display display = new Display();
final Shell shell = SWT_AWT.new_Shell(display,canvas);
shell.setLayout(new FillLayout());
Button button = new Button(shell,SWT.PUSH);
button.setText("SWT Button");
button.addSelectionListener(new SelectionListener()...{
public void widgetDefaultSelected(SelectionEvent e) ...{
}
public void widgetSelected(SelectionEvent e) ...{
SwingUtilities.invokeLater(new Runnable()...{
public void run()...{
frame.dispose();
}
});
}
});
frame.setSize(400,300);
while (!shell.isDisposed()) ...{
if (!display.readAndDispatch())...{
display.sleep ();
}
}
display.dispose();
}
SWT的透明效果(对控件无效)
public static void main(String[] args) ...{
final Display display = new Display();
final Shell shell = new Shell(display,SWT.NO_BACKGROUND);
shell.addPaintListener(new PaintListener() ...{
public void paintControl(PaintEvent e) ...{
GC gc = e.gc;
ImageData imageData = new ImageData("qd2.jpg");
imageData.alpha=90;
Image image = new Image(display, imageData);
gc.drawImage(image,0,0);
}
});
shell.setSize(400,300);
shell.open();
while (!shell.isDisposed()) ...{
if (!display.readAndDispatch())...{
display.sleep ();
}
}
display.dispose();
}
final Display display = new Display();
final Shell shell = new Shell(display,SWT.NO_BACKGROUND);
shell.addPaintListener(new PaintListener() ...{
public void paintControl(PaintEvent e) ...{
GC gc = e.gc;
ImageData imageData = new ImageData("qd2.jpg");
imageData.alpha=90;
Image image = new Image(display, imageData);
gc.drawImage(image,0,0);
}
});
shell.setSize(400,300);
shell.open();
while (!shell.isDisposed()) ...{
if (!display.readAndDispatch())...{
display.sleep ();
}
}
display.dispose();
}
- swt与awt/swing互嵌
- 关于SWT与AWT/Swing的关系
- SWT、Swing 或 AWT 比较与适用范围
- AWT 、Swing、SWT的区别与比较
- java swt与awt、swing区别
- AWT Swing SWT
- awt,swing,swt比较
- AWT、SWT 和 Swing
- AWT,SWT&SWING
- SWT、Swing 或 AWT
- AWT-SWT-Swing大比较之一:模型设计与实现
- Java中AWT、Swing与SWT三大GUI技术
- SWT, Swing and AWT[收藏]
- AWT,SWING, SWT, JFACE 比较
- SWT、Swing 和 AWT 介绍
- SWT:AWT和SWING的强大竞争者
- SWT:AWT和SWING的强大竞争者
- SWT:AWT和SWING的强大竞争者
- asp 防注入相关代码
- 使用gdi+的Image旋转图片并保存
- 用组件beanutils,dbutils简化JDBC操作
- 在ACCESS中如何添加、删除表的“索引:有(无重复)”属性?
- (转发)vb.net和c# 语法比较
- swt与awt/swing互嵌
- 在Access中创建表及如何指定字段类型
- Manning的新书 Ajax in Practice 发布了。
- 针对hibernate,jdbc,sql的思考
- 链路层(一)
- sql 日期函数详解
- 关于C#命令行参数教程
- Hacking swing: 一个JDBC表控件模型
- 部署和分发.NET应用程序的两种方法