主题:为什么按钮没有显现出来
为什么按钮没有显现出来
//查找
public void find()
{
JDialog findDialog=new JDialog(NotePad.this,"查找",false);
Container findPanel=findDialog.getContentPane();
JPanel fieldPane = new JPanel(),buttonPane=new JPanel();
JLabel find=new JLabel("查找内容(N):");
JLabel replace=new JLabel("替换为(P): ");
JTextField tofind=new JTextField(18);
JTextField toreplace=new JTextField(18);
JButton jbtfind=new JButton("查找下一个");
JButton jbtreplace=new JButton("替换");
JButton jbtfindnext=new JButton("全部替换");
JButton jbtcancel=new JButton("取消");
//fieldPane.setLayout(new GridLayout(2,2,3,3));
fieldPane.add(find);
fieldPane.add(tofind);
fieldPane.add(replace);
fieldPane.add(toreplace);
buttonPane.setLayout(null);
//jbtfind.setPreferredSize(new Dimension(80,30));
jbtfind.setSize(78, 30);
buttonPane.add(jbtfind);
buttonPane.add(jbtreplace);
buttonPane.add(jbtfindnext);
buttonPane.add(jbtcancel);
findPanel.setLayout(new BorderLayout());
findPanel.add(fieldPane,BorderLayout.CENTER);
findPanel.add(buttonPane,BorderLayout.EAST);
findDialog.setSize(400,170);
place(findDialog);
findDialog.setResizable(false);
findDialog.setVisible(true);
}
还有为什么要设成setLayout(null)才能改变按钮的大小
//查找
public void find()
{
JDialog findDialog=new JDialog(NotePad.this,"查找",false);
Container findPanel=findDialog.getContentPane();
JPanel fieldPane = new JPanel(),buttonPane=new JPanel();
JLabel find=new JLabel("查找内容(N):");
JLabel replace=new JLabel("替换为(P): ");
JTextField tofind=new JTextField(18);
JTextField toreplace=new JTextField(18);
JButton jbtfind=new JButton("查找下一个");
JButton jbtreplace=new JButton("替换");
JButton jbtfindnext=new JButton("全部替换");
JButton jbtcancel=new JButton("取消");
//fieldPane.setLayout(new GridLayout(2,2,3,3));
fieldPane.add(find);
fieldPane.add(tofind);
fieldPane.add(replace);
fieldPane.add(toreplace);
buttonPane.setLayout(null);
//jbtfind.setPreferredSize(new Dimension(80,30));
jbtfind.setSize(78, 30);
buttonPane.add(jbtfind);
buttonPane.add(jbtreplace);
buttonPane.add(jbtfindnext);
buttonPane.add(jbtcancel);
findPanel.setLayout(new BorderLayout());
findPanel.add(fieldPane,BorderLayout.CENTER);
findPanel.add(buttonPane,BorderLayout.EAST);
findDialog.setSize(400,170);
place(findDialog);
findDialog.setResizable(false);
findDialog.setVisible(true);
}
还有为什么要设成setLayout(null)才能改变按钮的大小