我想在 ID 下方制作密码标签和文本字段。但我对 GriBagLayout 有点陌生。
我希望你能帮助我。
这是我的代码:
class LoginPanel extends JPanel {//login components
private JButton exitbtn = new JButton("Exit");
private JLabel idLabel = new JLabel("Staff ID : ");
private JTextField idJtf = new JTextField(10);
private JLabel pwLabel = new JLabel("Password : ");
private JPasswordField pwJtf = new JPasswordField(10);
LoginPanel() {
setOpaque(false);
setLayout(new GridBagLayout());
setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
//add(new JLabel("Staff ID: ")); add(new JTextField(10));
//add(new JLabel("Password: ")); add(new JPasswordField(10));
add(idLabel);
add(idJtf);
add(pwLabel);
add(pwJtf);
//add(exitbtn);
}
}