jFrame背景图片设置
来源:互联网 发布:力士乐驱动器调试软件 编辑:程序博客网 时间:2024/06/06 00:31
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class BgTest extends JFrame{
public BgTest(){ init(); } private void init() { JLabel lbl1 = new JLabel("用户名:"); JLabel lbl2 = new JLabel("密 码:"); JTextField txt = new JTextField(10); JPasswordField pasw = new JPasswordField(10); pasw.setEchoChar('*'); JButton btn1 = new JButton("登录"); JButton btn2 = new JButton("取消"); ImageIcon img = new ImageIcon("images/bgTest.jpg"); //要设置的背景图片 JLabel imgLabel = new JLabel(img); //将背景图放在标签里。 this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE)); //将背景标签添加到jfram的LayeredPane面板里。 imgLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight()); // 设置背景标签的位置 Container contain = this.getContentPane(); ((JPanel) contain).setOpaque(false); // 将内容面板设为透明。将LayeredPane面板中的背景显示出来。 contain.setLayout(new FlowLayout()); contain.add(lbl1); contain.add(txt); contain.add(lbl2); contain.add(pasw); contain.add(btn1); contain.add(btn2); this.setTitle("背景图设置"); this.setSize(200, 200);//设置窗体大小 this.setLocation(600, 300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setResizable(false); this.setVisible(true); } public static void main(String[] args) { new BgTest(); }
}
设置Frame icon图标:
ImageIcon imgIcon = new ImageIcon("images/rear.gif"); Image img = imgIcon.getImage(); this.setIconImage(img);
0 0
- JFrame 设置背景图片方法
- JFrame中设置背景图片
- JFrame设置背景图片
- JFrame如何设置背景图片
- 设置JFrame的背景图片
- JFrame中设置背景图片
- JFrame如何设置背景图片
- Java - JFrame 设置背景图片
- jFrame背景图片设置
- JFrame设置背景图片
- [Java]JFrame如何设置背景图片
- 为jframe窗口设置背景图片
- JFrame设置背景图片的方法
- 为jframe窗口设置背景图片
- java如何设置JFrame背景图片
- 设置JPanel或jframe的背景图片
- Java 在JFrame中设置背景图片
- 设置JFrame的背景图片,实现Jtable 透明
- SQL语言简单的增删改查
- Python RuntimeError: maximum recursion depth exceeded in cmp 超过最大递归深度错误
- 安卓使用ContentProvider实现读取手机联系人和短信内容
- spark streaming 实现根据文件内容自定义文件名,并实现文件内容追加
- mac下安装python+opencv
- jFrame背景图片设置
- rails5 升级过程中遇到的问题
- 闲话
- Qt基类
- java基础知识(1)—一起加强加强java基础吧
- Android getContentResolver().query结果为空指针
- HTML5的基本知识
- SQLite Update 语句
- C++第1次实验(基础班)—初识C++