I have had this problem with big gaps between my boxes and fields in Java GUI, and its making programming in GUIs very frustrating.
As you see from the picture, there is a big space between the restart label and the checkbox. Also, the text field which only should be large enough to fit to numbers is too wide, even though I have set the size of it to (10, 10).
Could someone tell me what's going wrong here so that I can get this GUI the way I want it to look?
Here's my code:
private void initContent(GridPane pane) {
pane.setPadding(new Insets(10, 10, 10, 10));
pane.setHgap(10);
pane.setVgap(10);
//fonts
Font myfont = new Font("Serif", 18);
Font myfont2 = new Font("Serif", 30);
//Set time label above textfield
lblsetTime = new Label("Set time in minute");
lblsetTime.setFont(myfont);
pane.add(lblsetTime, 0, 3);
//Restart textfield
txfRestart = new TextField();
pane.add(txfRestart, 0, 4, 1, 1);
txfRestart.setPrefSize(10, 10);
txfRestart.setFont(myfont2);
//restart label & checkbox
lblRestart = new Label("Restart:");
pane.add(lblRestart, 0, 5);
chkRestart = new CheckBox();
pane.add(chkRestart, 1, 5);
//Shutdown label and checkbox
lblShutdown = new Label("Shutdown: ");
pane.add(lblShutdown, 0, 6);
chkShutdown = new CheckBox();
pane.add(chkShutdown, 2, 6);
}
Aucun commentaire:
Enregistrer un commentaire