swing的设置背景问题

泼墨豪 2013-04-20 03:26:44
怎么把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();
}
}
...全文
212 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
a_9_5_2_7 2013-06-12
  • 打赏
  • 举报
回复
引用 6 楼 pomohoIT 的回复:
[quote=引用 3 楼 a_9_5_2_7 的回复:] label1.setBounds(10, 自己调试位置, 120, 20); label2.setBounds(10, 自己调试位置,, 120, 20); textField.setBounds(135, 自己调试位置,, 120, 20); passwordField.setBounds(135, 自己调试位置,, 120, 20);
这样能把上面的东西一下去,但是界面上还是有最上面那一大块灰色的东西[/quote] 每个组件都有一个设置为透明的方法,具体的方法名忘了,这样就没有灰色了
泼墨豪 2013-04-21
  • 打赏
  • 举报
回复
引用 3 楼 a_9_5_2_7 的回复:
label1.setBounds(10, 自己调试位置, 120, 20); label2.setBounds(10, 自己调试位置,, 120, 20); textField.setBounds(135, 自己调试位置,, 120, 20); passwordField.setBounds(135, 自己调试位置,, 120, 20);
这样能把上面的东西一下去,但是界面上还是有最上面那一大块灰色的东西
静山晚风 2013-04-21
  • 打赏
  • 举报
回复
设置为边界布局
a1216164960 2013-04-20
  • 打赏
  • 举报
回复
的确你这种布局比较简单用楼上的用法比较容易 你可以下一个软件 是可以测量具体的位置的可以精准的放在你需要的地方
a_9_5_2_7 2013-04-20
  • 打赏
  • 举报
回复
label1.setBounds(10, 自己调试位置, 120, 20); label2.setBounds(10, 自己调试位置,, 120, 20); textField.setBounds(135, 自己调试位置,, 120, 20); passwordField.setBounds(135, 自己调试位置,, 120, 20);
LCore 2013-04-20
  • 打赏
  • 举报
回复
JFrame添加JPanel jpanel设置背景 jpanel中添加控件就行了
luke-skyworker 2013-04-20
  • 打赏
  • 举报
回复
正在学习,还不知道swing是啥玩意

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧