Jdialog的例子,为什么那个dialog里的控件不能控制大小啊?????????????
import java.awt.*;
import javax.swing.JButton;
import javax.swing.JDialog;
public class Dialoginput extends JDialog{
JButton jb,jc;
/**
*
*/
private static final long serialVersionUID = 1L;
Dialog parent;
Dialoginput(Frame f,String s,boolean modal)
{
super(f,s,modal);
parent=(Dialog)f;
jb=new JButton( "d ");
jb.setBounds(44, 44, 44, 33);
jc=new JButton( "ddd ");
jc.setBounds(44, 44, 44, 33);
add(jb);
add(jc);
this.setSize(100,100);
}
}
/////////////
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Dialog extends JFrame{
JButton jb;
Dialoginput diain;
Dialog()
{ Container content=getContentPane();
setSize(400,400);
setVisible(true);
setLayout(null);
jb=new JButton( "d ");
jb.setBounds(55, 55, 55, 55);
content.add(jb);
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
x(e);
}
});
}
public static void main(String [] agrs)
{
new Dialog();
}
public void x(ActionEvent e)
{
this.diain=new Dialoginput(this, "d ",true);
this.diain.show();
}
}
------解决方案--------------------
主要是需要一个布局管理器
1 ---------------------------
//Dialoginput(Frame f,String s,boolean modal)
Dialoginput(JFrame f,String s,boolean modal)
{
super(f,s,modal);
parent=(Dialog)f;
jb=new JButton( "d ");
jb.setBounds(44, 44, 44, 33);
jc=new JButton( "ddd ");
jc.setBounds(44, 44, 44, 33);
//布局管理
this.setLayout(new FlowLayout());
add(jb);
add(jc);
this.setSize(100,100);
}
2--------------------------
import javax.swing.JFrame;
Dialog()
{ Container content=getContentPane();
setSize(400,400);
//setVisible(true);
setLayout(null);
jb=new JButton( "d ");
jb.setBounds(55, 55, 55, 55);
content.add(jb);
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
x(e);
}
});
setVisible(true);//最后设置可以化.
}