List of usage examples for javafx.scene.layout HBox setAlignment
public final void setAlignment(Pos value)
From source file:Main.java
private static Node createConfirmationPanel() { final Label acceptanceLabel = new Label("Not Available"); final Button acceptButton = new Button("Accept"); acceptButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(final ActionEvent event) { acceptanceLabel.setText("Accepted"); }// w w w .java 2 s . c o m }); final Button declineButton = new Button("Decline"); declineButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(final ActionEvent event) { acceptanceLabel.setText("Declined"); } }); final HBox panel = createHBox(6, acceptButton, declineButton, acceptanceLabel); panel.setAlignment(Pos.CENTER_LEFT); configureBorder(panel); return panel; }
From source file:nl.mvdr.umvc3replayanalyser.gui.ErrorMessagePopup.java
/** * Handles an exception that caused program startup to fail, by showing an error message to the user. * //from w w w .jav a2 s.co m * @param title * title for the dialog * @param errorMessage * error message * @param stage * stage in which to show the error message * @param exception * exception that caused the error */ public static void show(String title, String errorMessage, final Stage stage, Exception exception) { log.info("Showing error message dialog to indicate that startup failed."); // Create the error dialog programatically without relying on FXML, to minimize the chances of further failure. stage.setTitle(title); // Error message text. Text text = new Text(errorMessage); // Text area containing the stack trace. Not visible by default. String stackTrace; if (exception != null) { stackTrace = ExceptionUtils.getStackTrace(exception); } else { stackTrace = "No more details available."; } final TextArea stackTraceArea = new TextArea(stackTrace); stackTraceArea.setEditable(false); stackTraceArea.setVisible(false); // Details button for displaying the stack trace. Button detailsButton = new Button(); detailsButton.setText("Details"); detailsButton.setOnAction(new EventHandler<ActionEvent>() { /** {@inheritDoc} */ @Override public void handle(ActionEvent event) { log.info("User clicked Details."); stackTraceArea.setVisible(!stackTraceArea.isVisible()); } }); // OK button for closing the dialog. Button okButton = new Button(); okButton.setText("OK"); okButton.setOnAction(new EventHandler<ActionEvent>() { /** {@inheritDoc} */ @Override public void handle(ActionEvent event) { log.info("User clicked OK, closing the dialog."); stage.close(); } }); // Horizontal box containing the buttons, to make sure they are always centered. HBox buttonsBox = new HBox(5); buttonsBox.getChildren().add(detailsButton); buttonsBox.getChildren().add(okButton); buttonsBox.setAlignment(Pos.CENTER); // Layout constraints. AnchorPane.setTopAnchor(text, Double.valueOf(5)); AnchorPane.setLeftAnchor(text, Double.valueOf(5)); AnchorPane.setRightAnchor(text, Double.valueOf(5)); AnchorPane.setTopAnchor(stackTraceArea, Double.valueOf(31)); AnchorPane.setLeftAnchor(stackTraceArea, Double.valueOf(5)); AnchorPane.setRightAnchor(stackTraceArea, Double.valueOf(5)); AnchorPane.setBottomAnchor(stackTraceArea, Double.valueOf(36)); AnchorPane.setLeftAnchor(buttonsBox, Double.valueOf(5)); AnchorPane.setRightAnchor(buttonsBox, Double.valueOf(5)); AnchorPane.setBottomAnchor(buttonsBox, Double.valueOf(5)); AnchorPane root = new AnchorPane(); root.getChildren().addAll(text, stackTraceArea, buttonsBox); stage.setScene(new Scene(root)); // Use a standard program icon if possible. try { stage.getIcons().add(Icons.get().getRandomPortrait()); } catch (IllegalStateException e) { log.warn("Failed to load icon for error dialog; proceeding with default JavaFX icon.", e); } stage.show(); // Default size should also be the minimum size. stage.setMinWidth(stage.getWidth()); stage.setMinHeight(stage.getHeight()); log.info("Error dialog displayed."); }
From source file:main.TestManager.java
/** * Displays given test. Intended for testing and * evaluating correct answers. (student mode only) * @param test test to display/*from ww w . j a v a2s. com*/ * @param stage */ public static void displayTest(Test test, Stage stage) { Debugger.println(test.getName() + " - is displayed."); TabPane tabPane = new TabPane(); int counter = 1; for (Question q : test.getQuestions()) { Label instruction = new Label(q.question); instruction.setStyle("-fx-font-size: 20"); Pane choices = q.getPaneOfChoices(); VBox vbox = new VBox(instruction, choices); vbox.setSpacing(10); Tab tab = new Tab("Otzka " + Integer.toString(counter), vbox); tab.setStyle("-fx-font-size: 20"); tabPane.getTabs().add(tab); counter++; } Button finish = new Button("Ukon?i test!"); finish.setStyle("-fx-font-size: 20"); finish.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { try { test.evaluate(stage); } catch (IOException e) { Alert alert = new Alert(AlertType.ERROR); alert.setContentText("Ojoj, vyskytol sa problm. Aplikcia sa mus ukon?i."); alert.showAndWait(); System.exit(0); } } }); Button nextQuestion = new Button("alia"); nextQuestion.setStyle("-fx-font-size: 20"); nextQuestion.setOnAction(e -> tabPane.getSelectionModel().selectNext()); HBox buttons = new HBox(finish, nextQuestion); buttons.setSpacing(10); buttons.setAlignment(Pos.BOTTOM_CENTER); VBox outerVBox = new VBox(tabPane, buttons); outerVBox.setPadding(new Insets(10, 10, 10, 10)); Scene scene = new Scene(outerVBox); stage.setScene(scene); stage.show(); }
From source file:Main.java
private static Node createLoginPanel() { final ToggleGroup toggleGroup = new ToggleGroup(); final TextField textField = new TextField(); textField.setPrefColumnCount(10);// w w w . j av a 2s . c om textField.setPromptText("Your name"); final PasswordField passwordField = new PasswordField(); passwordField.setPrefColumnCount(10); passwordField.setPromptText("Your password"); final ChoiceBox<String> choiceBox = new ChoiceBox<String>(FXCollections.observableArrayList("English", "\u0420\u0443\u0441\u0441\u043a\u0438\u0439", "Fran\u00E7ais")); choiceBox.setTooltip(new Tooltip("Your language")); choiceBox.getSelectionModel().select(0); final HBox panel = createHBox(6, createVBox(2, createRadioButton("High", toggleGroup, true), createRadioButton("Medium", toggleGroup, false), createRadioButton("Low", toggleGroup, false)), createVBox(2, textField, passwordField), choiceBox); panel.setAlignment(Pos.BOTTOM_LEFT); configureBorder(panel); return panel; }
From source file:com.github.drbookings.ui.controller.BookingDetailsController.java
private static void addRow4(final Pane content, final BookingBean be) { final HBox box = new HBox(); box.setPadding(new Insets(4)); box.setAlignment(Pos.CENTER_LEFT); box.setFillHeight(true);/* www. j av a 2 s. co m*/ final TextFlow tf = new TextFlow(); final Text t0 = new Text("Net Earnings: \t"); final Text netEarnings = new Text(String.format("%3.2f", be.getNetEarnings())); final Text t1 = new Text(" total \t"); final Text netEarningsDay = new Text(String.format("%3.2f", be.getNetEarnings() / be.getNumberOfNights())); final Text t2 = new Text(" /night"); tf.getChildren().addAll(t0, netEarnings, t1, netEarningsDay, t2); box.getChildren().addAll(tf); if (be.getNetEarnings() <= 0) { box.getStyleClass().addAll("warning", "warning-bg"); } content.getChildren().add(box); }
From source file:com.github.drbookings.ui.controller.BookingDetailsController.java
private static void addRow0(final Pane content, final BookingBean be) { final HBox box = new HBox(); final HBox boxName = new HBox(); final HBox boxDates = new HBox(); final HBox boxNights = new HBox(); box.setAlignment(Pos.CENTER); boxName.getStyleClass().add("first-line"); boxDates.getStyleClass().add("first-line"); boxNights.getStyleClass().add("first-line"); boxName.setPadding(boxPadding);//from w ww. ja v a2 s . co m boxDates.setPadding(boxPadding); boxNights.setPadding(boxPadding); boxName.setAlignment(Pos.CENTER); boxDates.setAlignment(Pos.CENTER); boxNights.setAlignment(Pos.CENTER); HBox.setHgrow(boxName, Priority.ALWAYS); HBox.setHgrow(boxDates, Priority.ALWAYS); HBox.setHgrow(boxNights, Priority.ALWAYS); addName(boxName, be); // box.getChildren().add(new Separator(Orientation.VERTICAL)); addDates(boxDates, be); // box.getChildren().add(new Separator(Orientation.VERTICAL)); addNights(boxNights, be); box.getChildren().addAll(boxName, boxDates, boxNights); box.getStyleClass().add(Styles.getBackgroundStyleSource(be.getBookingOrigin().getName())); content.getChildren().add(box); }
From source file:Main.java
@Override public void start(Stage stage) { Group root = new Group(); Scene scene = new Scene(root, 300, 150); stage.setScene(scene);/*from www.j a v a2 s . c o m*/ stage.setTitle("Progress Controls"); for (int i = 0; i < values.length; i++) { final Label label = labels[i] = new Label(); label.setText("progress:" + values[i]); final ProgressBar pb = pbs[i] = new ProgressBar(); pb.setProgress(values[i]); final ProgressIndicator pin = pins[i] = new ProgressIndicator(); pin.setProgress(values[i]); final HBox hb = hbs[i] = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, pb, pin); } final VBox vb = new VBox(); vb.setSpacing(5); vb.getChildren().addAll(hbs); scene.setRoot(vb); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setScene(scene);/*from www . j av a 2 s. co m*/ stage.show(); stage.setWidth(300); stage.setHeight(200); final String[] greetings = new String[] { "Hello", "Hola", "1", "2" }; final ChoiceBox cb = new ChoiceBox(FXCollections.observableArrayList("1", "2", "3", "4")); cb.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue ov, Number value, Number new_value) { System.out.println(new_value.intValue()); } }); cb.setValue("2"); HBox hb = new HBox(); hb.getChildren().addAll(cb); hb.setSpacing(30); hb.setAlignment(Pos.CENTER); hb.setPadding(new Insets(10, 0, 0, 10)); ((Group) scene.getRoot()).getChildren().add(hb); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Tabs"); Group root = new Group(); Scene scene = new Scene(root, 400, 250, Color.WHITE); TabPane tabPane = new TabPane(); BorderPane borderPane = new BorderPane(); for (int i = 0; i < 5; i++) { Tab tab = new Tab(); tab.setText("Tab" + i); HBox hbox = new HBox(); hbox.getChildren().add(new Label("Tab" + i)); hbox.setAlignment(Pos.CENTER); tab.setContent(hbox);/*from w w w .ja v a 2 s . c o m*/ tabPane.getTabs().add(tab); } // bind to take available space borderPane.prefHeightProperty().bind(scene.heightProperty()); borderPane.prefWidthProperty().bind(scene.widthProperty()); borderPane.setCenter(tabPane); root.getChildren().add(borderPane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Tabs"); Group root = new Group(); Scene scene = new Scene(root, 400, 250, Color.WHITE); TabPane tabPane = new TabPane(); BorderPane borderPane = new BorderPane(); for (int i = 0; i < 5; i++) { Tab tab = new Tab(); tab.setText("Tab" + i); HBox hbox = new HBox(); hbox.getChildren().add(new Label("Tab" + i)); hbox.setAlignment(Pos.CENTER); tab.setContent(hbox);//w w w . java 2 s . co m tabPane.getTabs().add(tab); } tabPane.setSide(Side.LEFT); //tabPane.setSide(Side.TOP); //tabPane.setSide(Side.RIGHT); //tabPane.setSide(Side.BOTTOM); // bind to take available space borderPane.prefHeightProperty().bind(scene.heightProperty()); borderPane.prefWidthProperty().bind(scene.widthProperty()); borderPane.setCenter(tabPane); root.getChildren().add(borderPane); primaryStage.setScene(scene); primaryStage.show(); }