Swing增加透明窗体及不规则窗体的方法

原创|其它|编辑:郝浩|2009-07-03 11:23:33.000|阅读 1112 次

概述:最新的JDK-6u10版本已经在进行beta测试,对于Swing来说,在此版本中增加了两个重要的功能:透明窗体和不规则窗体。

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

  最新的JDK-6u10版本已经在进行beta测试,对于Swing来说,在此版本中增加了两个重要的功能:透明窗体和不规则窗体。这两个功能使得swing也可以做出Vista下的玻璃效果来了,

  jdk-6u10还没有正式发布,可以在http://download.Java.net/jdk6/binaries/进行下载

  透明窗体:

点击查看大图

    publicclassTranslucentWindowextendsJFrame{
  publicTranslucentWindow(){
  super("透明窗体");
  this.setLayout(newFlowLayout());
  this.add(newJButton("按钮"));
  this.add(newJCheckBox("复选按钮"));
  this.add(newJRadioButton("单选按钮"));
  this.add(newJProgressBar(20,100));
  this.setSize(newDimension(400,300));
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  publicstaticvoidmain(String[]args){
  JFrame.setDefaultLookAndFeelDecorated(true);
  SwingUtilities.invokeLater(newRunnable(){
  publicvoidrun(){
  Windoww=newTranslucentWindow();
  w.setVisible(true);
  com.sun.awt.AWTUtilities.setWindowOpacity(w,0.6f);
  }
  });
  }
  }
  publicclassTranslucentWindowextendsJFrame{
  publicTranslucentWindow(){
  super("透明窗体");
  this.setLayout(newFlowLayout());
  this.add(newJButton("按钮"));
  this.add(newJCheckBox("复选按钮"));
  this.add(newJRadioButton("单选按钮"));
  this.add(newJProgressBar(20,100));
  this.setSize(newDimension(400,300));
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  publicstaticvoidmain(String[]args){
  JFrame.setDefaultLookAndFeelDecorated(true);
  SwingUtilities.invokeLater(newRunnable(){
  publicvoidrun(){
  Windoww=newTranslucentWindow();
  w.setVisible(true);
  com.sun.awt.AWTUtilities.setWindowOpacity(w,0.6f);
  }
  });
  }
  }

  不规则窗体:

点击查看大图

 
   publicclassShapedWindowextendsJFrame{
  publicShapedWindow(){
  super("不规则窗体");
  this.setLayout(newFlowLayout());
  this.add(newJButton("按钮"));
  this.add(newJCheckBox("复选按钮"));
  this.add(newJRadioButton("单选按钮"));
  this.add(newJProgressBar(0,100));
  this.setSize(newDimension(400,400));
  this.setLocationRelativeTo(null);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  publicstaticvoidmain(String[]args){
  JFrame.setDefaultLookAndFeelDecorated(true);
  SwingUtilities.invokeLater(newRunnable(){
  publicvoidrun(){
  Windoww=newShapedWindow();
  w.setVisible(true);
  com.sun.awt.AWTUtilities.setWindowshape(w,newEllipse2D.Double(0,0,w.getWidth(),w.getHeight()));
  com.sun.awt.AWTUtilities.setWindowOpacity(w,0.93f);
  }
  });
  }
  }
  publicclassShapedWindowextendsJFrame{
  publicShapedWindow(){
  super("不规则窗体");
  this.setLayout(newFlowLayout());
  this.add(newJButton("按钮"));
  this.add(newJCheckBox("复选按钮"));
  this.add(newJRadioButton("单选按钮"));
  this.add(newJProgressBar(0,100));
  this.setSize(newDimension(400,400));
  this.setLocationRelativeTo(null);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  publicstaticvoidmain(String[]args){
  JFrame.setDefaultLookAndFeelDecorated(true);
  SwingUtilities.invokeLater(newRunnable(){
  publicvoidrun(){
  Windoww=newShapedWindow();
  w.setVisible(true);
  com.sun.awt.AWTUtilities.setWindowshape(w,newEllipse2D.Double(0,0,w.getWidth(),w.getHeight()));
  com.sun.awt.AWTUtilities.setWindowOpacity(w,0.93f);
  }
  });
  }
  }


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com

文章转载自:IT专家网论坛

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP