在以下代码中,组件正确显示但我们无法写入JTextField
。
public class CurrentOPDDetail extends JInternalFrame
{
JLabel[] line=new JLabel[10];
JLabel[] lbl=new JLabel[33];
JTextField txtName=new JTextField();
JTextField txtAge=new JTextField();
JTextField txtSex=new JTextField();
JTextField txtWeight=new JTextField();
public CurrentOPDDetail(int n)
{
super("OPD Detail Form",false,false);//Title, Resizable, closable
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setSize(screenSize.width-500,650);
setLocation(170,10);
setVisible(true);
setLayout(null);
lbl[0]=new JLabel("NAME");
lbl[1]=new JLabel("AGE");
lbl[2]=new JLabel("SEX");
lbl[3]=new JLabel("WEIGHT");
lbl[4]=new JLabel("HISTORY");
for(int i=0;i<10;i++)
{
line[i]=new JLabel("");
line[i].setBackground(Color.BLACK);
line[i].setOpaque(true);
}
lbl[0].setBounds(1, 5, 40, 25);
txtName.setBounds(41, 5, 200, 25);
lbl[1].setBounds(262, 5, 30, 25);
txtAge.setBounds(293, 5, 50, 25);
lbl[2].setBounds(370, 5, 30, 25);
txtSex.setBounds(400, 5, 50, 25);
lbl[3].setBounds(470, 5, 50, 25);
txtWeight.setBounds(520, 5, 100, 25);
line[0].setBounds(1, 33, screenSize.width-499, 5);
lbl[4].setBounds(1, 40, 150, 25);
add(line[0]);
add(lbl[0]);
add(txtName);
add(lbl[1]);
add(txtAge);
add(lbl[2]);
add(txtSex);
add(lbl[3]);
add(txtWeight);
}
}
答案 0 :(得分:3)
只需使用JFrame
和getContentPane().add()
即可。
内部窗口的文本字段可以正常工作:
JFrame frame = new JFrame();
frame.getContentPane().add(new CurrentOPDDetail(5));
frame.setVisible(true);