Home > Back-end >  Java GUI GridBagLayout layout generated component is too small
Java GUI GridBagLayout layout generated component is too small

Time:02-21

This is to achieve the effect of the

Consult everybody: something wrong with the big code
 public class TestDemo {
Public static void main (String [] args) {
JFrame frame=new JFrame (" my forms ");
Frame. SetDefaultCloseOperation (JFrame. EXIT_ON_CLOSE);
Frame. SetSize (640, 640);
JPanel panel=new JPanel ();
A panel. The setSize (640640);
Frame. SetResizable (false);
Frame. SetLocationRelativeTo (null);
GridBagLayout GridBagLayout=new GridBagLayout ();
The panel. SetLayout (gridBagLayout);
GridBagConstraints constraints=new GridBagConstraints ();
Constraints. The fill=GridBagConstraints. BOTH;
Constraints. Gridx=1;
Constraints. Gridy=2;
Constraints. Gridwidth=3;
Constraints. Gridheight=3;
JTextArea textArea=new JTextArea (" text area ");
GridBagLayout. SetConstraints (textArea, constraints);
Constraints. Gridx=4;
Constraints. Gridy=2;
Constraints. Gridwidth=1;
Constraints. Gridheight=1;
JButton buttonConfirm=new JButton (" ok ");
GridBagLayout. SetConstraints (buttonConfirm, constraints);
Constraints. Gridx=5;
Constraints. Gridy=2;
Constraints. Gridwidth=2;
Constraints. Gridheight=1;
JButton buttonCancel=new JButton (" cancel ");
GridBagLayout. SetConstraints (buttonCancel, constraints);
ButtonGroup group=new ButtonGroup ();
Constraints. Gridx=4;
Constraints. Gridy=3;
Constraints. Gridwidth=1;
Constraints. Gridheight=1;
JRadioButton buttonBold=new JRadioButton (" bold ");
GridBagLayout. SetConstraints (buttonBold, constraints);
Constraints. Gridx=5;
Constraints. Gridy=3;
Constraints. Gridwidth=2;
Constraints. Gridheight=1;
JRadioButton buttonItalic=new JRadioButton (" italics ");
GridBagLayout. SetConstraints (buttonItalic, constraints);
Constraints. Gridx=4;
Constraints. Gridy=4;
Constraints. Gridwidth=2;
Constraints. Gridheight=1;
JRadioButton buttonCommon=new JRadioButton (" conventional ");
GridBagLayout. SetConstraints (buttonCommon, constraints);
Constraints. Gridx=5;
Constraints. Gridy=4;
Constraints. Gridwidth=2;
Constraints. Gridheight=1;
JRadioButton buttonBoldItalic=new JRadioButton ("/font ");
GridBagLayout. SetConstraints (buttonBoldItalic, constraints);
Constraints. Gridx=1;
Constraints. Gridy=5;
Constraints. Gridwidth=6;
Constraints. Gridheight=1;
JTextField textField=new JTextField (" enter your name ");
GridBagLayout. SetConstraints (textField, constraints);
Group. The add (buttonBold);
Group. The add (buttonItalic);
Group. The add (buttonCommon);
Group. The add (buttonBoldItalic);
A panel. The add (textArea);
A panel. The add (buttonConfirm);
A panel. The add (buttonCancel);
A panel. The add (buttonBold);
A panel. The add (buttonItalic);
A panel. The add (buttonCommon);
A panel. The add (buttonBoldItalic);
A panel. The add (textField);
Frame. The add (panel);
Frame. SetVisible (true);
}
}
  • Related