lab-04/NewAccount:

- FlowPane with HBox panes in col
	- Make buttons HBox
This commit is contained in:
HeshamTB 2020-10-24 13:16:14 +03:00
parent 180f59c2d9
commit 7f41f45acd
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -2,18 +2,17 @@ package sample;
import javafx.application.Application; import javafx.application.Application;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.geometry.HPos; import javafx.geometry.*;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.VPos;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox; import javafx.scene.control.ComboBox;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane; import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
/* /*
@ -38,42 +37,29 @@ public class Main extends Application {
root.setColumnHalignment(HPos.CENTER); root.setColumnHalignment(HPos.CENTER);
root.setRowValignment(VPos.CENTER); root.setRowValignment(VPos.CENTER);
root.setHgap(10); root.setHgap(10);
root.setVgap(15); root.setVgap(5);
root.setMaxWidth(270); root.setMaxWidth(270);
root.setPrefWrapLength(250); root.setPrefWrapLength(250);
//Labels //Panes (HBoxes)
Label lFirstName = new Label("First name: "); HBox boxFirstName = makeLebelWithText("First name: ");
Label lLasttName = new Label("Last name: "); HBox boxLasttName = makeLebelWithText("Last name: ");
Label lPassword = new Label("Enter password: "); HBox boxPassword = makeLebelWithText("Enter password");
Label lRePass = new Label("Reenter password: "); HBox boxRePass = makeLebelWithText("Reenter password: ");
Label lCity = new Label("City: "); HBox boxCity = makeLebelWithText("City");
Label lCountry = new Label("Choose a counrty: "); HBox boxCountry = makeComboBoxWithLabel("Choose a country: ");
HBox boxButtons = makeButtons();
//Set mnemonic root.getChildren().addAll(boxFirstName,
lFirstName.setMnemonicParsing(true);// makes tab work or Alt+n boxLasttName,
lLasttName.setMnemonicParsing(true); boxPassword,
lPassword.setMnemonicParsing(true); boxRePass,
lRePass.setMnemonicParsing(true); boxCountry,
lCity.setMnemonicParsing(true); boxCity,
boxButtons);
//Text fields
TextField fFirstName = new TextField();
TextField fLastName = new TextField();
TextField fPassword = new TextField();
TextField fRepass = new TextField();
TextField fCity = new TextField();
ComboBox<String> comCountry = new ComboBox<>(FXCollections.observableArrayList(Countries));
root.getChildren().addAll(lFirstName, fFirstName,
lLasttName, fLastName,
lPassword, fPassword,
lRePass, fRepass,
lCountry, comCountry,
lCity, fCity);
primaryStage.setTitle("Create new account"); primaryStage.setTitle("Create new account");
primaryStage.setScene(new Scene(root, 285, 300)); primaryStage.setScene(new Scene(root, 285, 350));
primaryStage.show(); primaryStage.show();
} }
@ -82,7 +68,7 @@ public class Main extends Application {
launch(args); launch(args);
} }
private Node makeLebelWithText(String labelText){ private HBox makeLebelWithText(String labelText){
HBox node = new HBox(); HBox node = new HBox();
node.setPadding(new Insets(10)); node.setPadding(new Insets(10));
node.setSpacing(10); node.setSpacing(10);
@ -92,7 +78,7 @@ public class Main extends Application {
return node; return node;
} }
private Node makeComboBoxWithLabel(String labelText) { private HBox makeComboBoxWithLabel(String labelText) {
HBox node = new HBox(); HBox node = new HBox();
node.setPadding(new Insets(10)); node.setPadding(new Insets(10));
node.setSpacing(10); node.setSpacing(10);
@ -101,4 +87,17 @@ public class Main extends Application {
return node; return node;
} }
private HBox makeButtons(){
HBox node = new HBox();
node.setPadding(new Insets(10));
node.setSpacing(10);
node.setAlignment(Pos.CENTER);
Button bClear = new Button("Clear");
Button bRegister = new Button("Register");
bClear.setPrefSize(100, 20);
bRegister.setPrefSize(100, 20);
node.getChildren().addAll(bClear,bRegister);
return node;
}
} }