zoukankan      html  css  js  c++  java
  • JFrame如何设置背景图片

    代码:

    import java.awt.FlowLayout;

    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;

    public class JFrameBackground {

     private JFrame frame = new JFrame("背景图片测试");

     private JPanel imagePanel;

     private ImageIcon background;

     public static void main(String[] args) {
      new JFrameBackground();
     }

     public JFrameBackground() {
      background = new ImageIcon("003.jpg");// 背景图片
      JLabel label = new JLabel(background);// 把背景图片显示在一个标签里面
      // 把标签的大小位置设置为图片刚好填充整个面板
      label.setBounds(0, 0, background.getIconWidth(),
        background.getIconHeight());
      // 把内容窗格转化为JPanel,否则不能用方法setOpaque()来使内容窗格透明
      imagePanel = (JPanel) frame.getContentPane();
      imagePanel.setOpaque(false);
      // 内容窗格默认的布局管理器为BorderLayout
      imagePanel.setLayout(new FlowLayout());
      imagePanel.add(new JButton("测试按钮"));

      frame.getLayeredPane().setLayout(null);
      // 把背景图片添加到分层窗格的最底层作为背景
      frame.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(background.getIconWidth(), background.getIconHeight());
      frame.setResizable(false);
      frame.setVisible(true);
     }
    }

  • 相关阅读:
    SAP中的文档维护
    SAP日期处理函数汇总(转)
    PR PO通过fm创建时,如何传输增强字段
    html+jQuery简单的利息计算器
    上传项目到github
    Nodejs-毕业设计5-小技巧
    Nodejs-毕业设计4-登录页面
    Nodejs-毕业设计3-路径
    Nodejs-毕业设计2-下载依赖准备工作
    Nodejs-毕业设计1-部署环境
  • 原文地址:https://www.cnblogs.com/tianguook/p/2382217.html
Copyright © 2011-2022 走看看