По нажатию кнопки должен создаваться экземпляр класса Adder
, который создает новый объект JFrame
поверх первого, но добавлении в него элементов при помощи GridBagConstraints
выкидывает java.lang.IllegalArgumentException: adding a window to a container
и закрывает программу.
public class Adder {
public Adder(){
JFrame frame = new JFrame();
frame.setLocationRelativeTo(null);
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLayout(new GridBagLayout());
JLabel nameLabel = new JLabel("Имя");
nameLabel.add(frame, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.9,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
JTextField name = new JTextField();
name.add(frame, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.9,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
frame.setVisible(true);
}
}