使用空布局控件无法显示

brooklyng60 2009-12-08 05:14:33
在SWING中使用空布局后,在界面中怎么一个控件都没显示啊。
跟每个控件都设置了坐标的setBounds(10,10,101,10);类似这样
然后加到panel中,也设置了panel的坐标
而且panel也设置了visible,size,
panel.setVisible(true);
panel.setSize(500,300);这样的,怎么还是不显示啊,各位大侠帮下小弟,才学JAVA没多久,谢谢了
...全文
188 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
brooklyng60 2009-12-13
  • 打赏
  • 举报
回复
panel.setBorder(BorderFactory.createEmptyBorder(20,20, 20, 20));
panel.setLayout(null);
panel.setVisible(true);//窗口可见
panel.setSize(500, 400);
txtIPaddress=new JTextField("localhost");
txtPort=new JTextField("3306");
txtdbName=new JTextField("databasename");
txtuserName=new JTextField();
txtpassword=new JTextField();
panel.add(lblIPaddress);
lblIPaddress.setBounds(50, 10, 50, 30);
panel.add(txtIPaddress);
txtIPaddress.setBounds(150, 10, 150, 30);
panel.add(lblPort);
lblPort.setBounds(50, 50, 50, 30);
panel.add(txtPort);
txtPort.setBounds(150, 50, 150, 30);
panel.add(lbldbName);
lbldbName.setBounds(50, 90, 60, 30);
panel.add(txtdbName);
txtdbName.setBounds(150, 90, 150, 30);
panel.add(lbluserName);
lbluserName.setBounds(50, 130, 60, 30);
panel.add(txtuserName);
txtuserName.setBounds(150, 130, 150, 30);
panel.add(lblPassword);
lblPassword.setBounds(50, 170, 60, 30);
panel.add(txtpassword);
txtpassword.setBounds(150, 170, 150, 30);
btnConfirm.setEnabled(false);//初始化时确定不可用,连接测试成功后方可以确定
panel.add(btntext);
panel.add(btnConfirm);
btntext.setBounds(320, 170, 60, 30);
btnConfirm.setBounds(400, 170, 60, 30);

panel.add(rdo_mysql);
panel.add(rdo_sqlserver);
panel.add(rdo_oracle);
rdo_mysql.setBounds(50, 250, 80, 30);
rdo_sqlserver.setBounds(150, 250, 80, 30);
rdo_oracle.setBounds(280, 250, 80, 30);
buttongroup=new ButtonGroup();
buttongroup.add(this.rdo_mysql);
buttongroup.add(this.rdo_sqlserver);
buttongroup.add(this.rdo_oracle);
365810247 2009-12-11
  • 打赏
  • 举报
回复
panel.setVisible(true); 这句可以不用加的.不显示.把代码贴出来看一下.或者有没有抛异常....
realreachard 2009-12-11
  • 打赏
  • 举报
回复
代码.
huntor 2009-12-11
  • 打赏
  • 举报
回复
看一示例,仅是展示null布局
import java.awt.event.*;
import javax.swing.*;
public class NoLayoutExample extends JFrame {

public NoLayoutExample(String name) {
super(name);

JTextField newItemField;
JList itemsList;
JButton addButton;
JButton removeButton;

getContentPane().setLayout(null);

//The text field
newItemField = new JTextField();
newItemField.setLocation(12,12);
newItemField.setSize(150,30);
getContentPane().add(newItemField);

//The Add button
addButton = new JButton("Add");
addButton.setMnemonic('A');
addButton.setLocation(174, 12);
addButton.setSize(100,30);
getContentPane().add(addButton);

//The List
itemsList = new JList();
JScrollPane scrollPane = new JScrollPane(itemsList,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setLocation(12,45);
scrollPane.setSize(150,150);
getContentPane().add(scrollPane);

//The Remove button
removeButton = new JButton("Remove");
removeButton.setMnemonic('R');
removeButton.setLocation(174,45);
removeButton.setSize(100,30);
getContentPane().add(removeButton);
}

public static void main(String[] args) {
JFrame frame = new NoLayoutExample("NULL Example");
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setSize(286, 230);
frame.setResizable(false);
frame.setVisible(true);
}
}
vincent3088 2009-12-10
  • 打赏
  • 举报
回复
加上下面这句问题就可以解决了:panel.setLayout(null);
GreenVesture 2009-12-10
  • 打赏
  • 举报
回复
代码贴上来瞅瞅...
mich_mia 2009-12-10
  • 打赏
  • 举报
回复
看不大明白,也是初学者。估计还是panel的 可见性设置有问题吧!
慢慢来吧.

58,454

社区成员

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

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