I’m kinda new to java swing and I’m trying to do this by hand for practice. In the following example, I have a setup where I have a GridLayout to display fields the way I want. But I need to re-size the text fields, since I don’t want them to all be that constant size. I need some to be bigger or smaller. Is there a way to do this? Also is there a way to remove some of the padding after the labels?
public void setupFrame() {
pnlTop.setLayout(new GridLayout(3, 4, 10, 10));
lblClosetLoc.setText("Closet location:");
lblPhone1.setText("Phone 1:");
lblJackPaired.setText("Jack paired:");
lblPhone2.setText("Phone 2:");
lblCubicle.setText("Cubicle:");
lblJackType.setText("Jack type:");
txtClosetLoc.setEditable(false);
txtClosetLoc.setText("");
txtPhone1.setEditable(false);
txtPhone1.setText("");
txtJackPaired.setEditable(false);
txtJackPaired.setText("");
txtPhone2.setEditable(false);
txtPhone2.setText("");
txtCubicle.setEditable(false);
txtCubicle.setText("");
txtJackType.setEditable(false);
txtJackType.setText("");
pnlTop.add(lblClosetLoc);
pnlTop.add(txtClosetLoc);
pnlTop.add(lblPhone1);
pnlTop.add(txtPhone1);
pnlTop.add(lblJackPaired);
pnlTop.add(txtJackPaired);
pnlTop.add(lblPhone2);
pnlTop.add(txtPhone2);
pnlTop.add(lblCubicle);
pnlTop.add(txtCubicle);
pnlTop.add(lblJackType);
pnlTop.add(txtJackType);
getContentPane().add(pnlTop);
setTitle("Test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(300, 300);
pack();
}
basic property of
GridLayoutis that resize its child in both direction andfills/schrinksall available area came from its parentpading are defined by
.... 10, 10)in thepnlTop.setLayout(new GridLayout(3, 4, 10, 10));have to look at
GridBagLayoutorSpringLayout