java中布局问题
JLabeljl=newJLabel("lggghhh");JPaneljp1=newJPanel();add(jp1,"North");jp1.add(jl);jp1....
JLabel jl=new JLabel("lggghhh");
JPanel jp1=new JPanel();
add(jp1,"North");
jp1.add(jl);
jp1.setLayout(null);
jl.setBounds(2, 2, 2, 2);
setTitle("ghjghjghj窗体中使用了面板");
setSize(600, 600);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);为什么我用了jl.setBounds(2, 2, 2, 2);
他的位置还是不会变呢?请高手帮忙下 非常感谢 ! 展开
JPanel jp1=new JPanel();
add(jp1,"North");
jp1.add(jl);
jp1.setLayout(null);
jl.setBounds(2, 2, 2, 2);
setTitle("ghjghjghj窗体中使用了面板");
setSize(600, 600);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);为什么我用了jl.setBounds(2, 2, 2, 2);
他的位置还是不会变呢?请高手帮忙下 非常感谢 ! 展开
2个回答
展开全部
我完全用的手动布局看看或许对你有帮助
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
public class Login extends JDialog{
JTextField jfid=null;
JPasswordField jfpwd=null;
JLabel lblid=null,lblpwd=null;
JButton jblog=null,jbclear=null;
public Login(){
Container ct = this.getContentPane();
setLayout(null);
lblid = new JLabel("账号:");
lblpwd = new JLabel("密码:");
jfid = new JTextField(20);
jfpwd = new JPasswordField(20);
jbclear = new JButton("清空");
jblog = new JButton("登陆");
backimage.setBounds(0,0,350,300);
lblid.setBounds(90,100,30,15);
jfid.setBounds(120,95,176,25);
lblpwd.setBounds(90,140,30,15);
jfpwd.setBounds(120,135,176,25);
jbclear.setBounds(120,180,70,30);
jblog.setBounds(225,180,70,30);
ct.add(lblid);
ct.add(jfid);
ct.add(lblpwd);
ct.add(jfpwd);
ct.add(jbclear);
ct.add(jblog);
this.setUndecorated(true);
int width = Toolkit.getDefaultToolkit().getScreenSize().width;
int height= Toolkit.getDefaultToolkit().getScreenSize().height;
this.setBounds(width/2-180, height/2-100, 350, 300);
this.setVisible(true);
}
public static void main(String[] args) {
new Login();
}
}
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
public class Login extends JDialog{
JTextField jfid=null;
JPasswordField jfpwd=null;
JLabel lblid=null,lblpwd=null;
JButton jblog=null,jbclear=null;
public Login(){
Container ct = this.getContentPane();
setLayout(null);
lblid = new JLabel("账号:");
lblpwd = new JLabel("密码:");
jfid = new JTextField(20);
jfpwd = new JPasswordField(20);
jbclear = new JButton("清空");
jblog = new JButton("登陆");
backimage.setBounds(0,0,350,300);
lblid.setBounds(90,100,30,15);
jfid.setBounds(120,95,176,25);
lblpwd.setBounds(90,140,30,15);
jfpwd.setBounds(120,135,176,25);
jbclear.setBounds(120,180,70,30);
jblog.setBounds(225,180,70,30);
ct.add(lblid);
ct.add(jfid);
ct.add(lblpwd);
ct.add(jfpwd);
ct.add(jbclear);
ct.add(jblog);
this.setUndecorated(true);
int width = Toolkit.getDefaultToolkit().getScreenSize().width;
int height= Toolkit.getDefaultToolkit().getScreenSize().height;
this.setBounds(width/2-180, height/2-100, 350, 300);
this.setVisible(true);
}
public static void main(String[] args) {
new Login();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询