lab-04/NewAccount:

- Manually add all elements
	- Will change to stackpane with Hboxes in a row
This commit is contained in:
HeshamTB 2020-10-24 12:40:34 +03:00
parent e3d930d67f
commit 180f59c2d9
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -1,13 +1,19 @@
package sample; package sample;
import javafx.application.Application; import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.geometry.HPos; import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Orientation; import javafx.geometry.Orientation;
import javafx.geometry.Pos; import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.Scene; import javafx.scene.Scene;
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.Pane;
import javafx.stage.Stage; import javafx.stage.Stage;
/* /*
@ -17,23 +23,57 @@ Using reference for flow panes:
*/ */
public class Main extends Application { public class Main extends Application {
private String[] Countries = {"Afghanistan","Albania","Andorra","Argentina","Armenia","Bangladesh",
"Barbados","Belgium","Belize","Benin","Burkina","Cameroon","Colombia","Costa Rica","Egypt",
"Fiji","France","Gambia","Guatemala","Iceland","India","Italy","Jamaica","Korea South","Kosovo",
"Kyrgyzstan","Libya","Liechtenstein","Malawi","Mexico","Micronesia","Moldova","Monaco","Morocco",
"Namibia","Netherlands","Oman","Pakistan","Philippines","Russia","Samoa","Saudi Arabia","Serbia",
"Seychelles","Sierra Leone","Suriname","Switzerland","Syria","Tanzania","Tunisia","Turkey","Uganda",
"Vietnam","Yemen"};
@Override @Override
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
FlowPane root = new FlowPane(Orientation.HORIZONTAL); FlowPane root = new FlowPane(Orientation.HORIZONTAL);
root.setColumnHalignment(HPos.LEFT); root.setColumnHalignment(HPos.CENTER);
root.setRowValignment(VPos.CENTER);
root.setHgap(10); root.setHgap(10);
root.setVgap(15); root.setVgap(15);
root.setMaxWidth(275); root.setMaxWidth(270);
root.setPrefWrapLength(270); root.setPrefWrapLength(250);
//Labels
Label lFirstName = new Label("First name: "); Label lFirstName = new Label("First name: ");
Label lLasttName = new Label("Last name: ");
Label lPassword = new Label("Enter password: ");
Label lRePass = new Label("Reenter password: ");
Label lCity = new Label("City: ");
Label lCountry = new Label("Choose a counrty: ");
//Set mnemonic
lFirstName.setMnemonicParsing(true);// makes tab work or Alt+n lFirstName.setMnemonicParsing(true);// makes tab work or Alt+n
lLasttName.setMnemonicParsing(true);
lPassword.setMnemonicParsing(true);
lRePass.setMnemonicParsing(true);
lCity.setMnemonicParsing(true);
//Text fields
TextField fFirstName = new TextField(); TextField fFirstName = new TextField();
lFirstName.setLabelFor(fFirstName); TextField fLastName = new TextField();
root.getChildren().addAll(lFirstName, fFirstName); 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, 300, 275)); primaryStage.setScene(new Scene(root, 285, 300));
primaryStage.show(); primaryStage.show();
} }
@ -41,4 +81,24 @@ public class Main extends Application {
public static void main(String[] args) { public static void main(String[] args) {
launch(args); launch(args);
} }
private Node makeLebelWithText(String labelText){
HBox node = new HBox();
node.setPadding(new Insets(10));
node.setSpacing(10);
Label label = new Label(labelText);
TextField textField = new TextField();
node.getChildren().addAll(label, textField);
return node;
}
private Node makeComboBoxWithLabel(String labelText) {
HBox node = new HBox();
node.setPadding(new Insets(10));
node.setSpacing(10);
Label label = new Label(labelText);
node.getChildren().addAll(label, new ComboBox<>(FXCollections.observableArrayList(Countries)));
return node;
}
} }