swing的设置背景问题

泼墨豪 泼墨豪 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
怎么把login和password以及后面的文本框移下去


package test;
import java.awt.Container;
import java.io.File;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
class BackgroundFrame extends JFrame{
public BackgroundFrame(){
super.setTitle("test background");
container = this.getContentPane();
textField = new JTextField(30);
passwordField = new JPasswordField();
imgLabel = new JLabel(image);
this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
label1 = new JLabel("login");
label2 = new JLabel("password");
imgLabel.setBounds(0, 0, image.getIconWidth(), image.getIconWidth());
label1.setBounds(10, 10, 120, 20);
label2.setBounds(10, 35, 120, 20);
textField.setBounds(135, 10, 120, 20);
passwordField.setBounds(135, 35, 120, 20);
this.setLayout(null);
container.add(label1);
container.add(label2);
container.add(passwordField);
container.add(textField);
container.add(imgLabel);
((JPanel)container).setOpaque(false);//将container设置成透明
super.setSize(image.getIconWidth(), image.getIconHeight());
super.setLocation(200, 100);
super.setVisible(true);
}
private JTextField textField;
private JLabel imgLabel;
private JLabel label1;
private JLabel label2;
private JPasswordField passwordField;
private Container container;
private String picPath = "c:" +File.separator + "background1.jpg";
private Icon image = new ImageIcon(picPath);
}
public class testBackground {
public static void main(String[] args) {
new BackgroundFrame();
}
}
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
泼墨豪
Java SE 62,621 成员 307,251 内容