List of usage examples for javafx.scene.layout ColumnConstraints ColumnConstraints
public ColumnConstraints(double minWidth, double prefWidth, double maxWidth)
From source file:Main.java
@Override public void start(Stage primaryStage) { BorderPane root = new BorderPane(); Scene scene = new Scene(root, 400, 250, Color.WHITE); GridPane gridpane = new GridPane(); gridpane.setPadding(new Insets(5)); gridpane.setHgap(10);//from w w w .ja v a 2s. co m gridpane.setVgap(10); ColumnConstraints column1 = new ColumnConstraints(150, 150, Double.MAX_VALUE); ColumnConstraints column2 = new ColumnConstraints(50); ColumnConstraints column3 = new ColumnConstraints(150, 150, Double.MAX_VALUE); column1.setHgrow(Priority.ALWAYS); column3.setHgrow(Priority.ALWAYS); gridpane.getColumnConstraints().addAll(column1, column2, column3); Label candidatesLbl = new Label("Candidates"); GridPane.setHalignment(candidatesLbl, HPos.CENTER); gridpane.add(candidatesLbl, 0, 0); Label selectedLbl = new Label("selected"); gridpane.add(selectedLbl, 2, 0); GridPane.setHalignment(selectedLbl, HPos.CENTER); // Candidates final ObservableList<String> candidates = FXCollections.observableArrayList("Z", "A", "B", "C", "D"); final ListView<String> candidatesListView = new ListView<>(candidates); gridpane.add(candidatesListView, 0, 1); final ObservableList<String> selected = FXCollections.observableArrayList(); final ListView<String> heroListView = new ListView<>(selected); gridpane.add(heroListView, 2, 1); Button sendRightButton = new Button(" > "); sendRightButton.setOnAction((ActionEvent event) -> { String potential = candidatesListView.getSelectionModel().getSelectedItem(); if (potential != null) { candidatesListView.getSelectionModel().clearSelection(); candidates.remove(potential); selected.add(potential); } }); Button sendLeftButton = new Button(" < "); sendLeftButton.setOnAction((ActionEvent event) -> { String s = heroListView.getSelectionModel().getSelectedItem(); if (s != null) { heroListView.getSelectionModel().clearSelection(); selected.remove(s); candidates.add(s); } }); VBox vbox = new VBox(5); vbox.getChildren().addAll(sendRightButton, sendLeftButton); gridpane.add(vbox, 1, 1); root.setCenter(gridpane); GridPane.setVgrow(root, Priority.ALWAYS); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { BorderPane root = new BorderPane(); Scene scene = new Scene(root, 400, 250, Color.WHITE); GridPane gridpane = new GridPane(); gridpane.setPadding(new Insets(5)); gridpane.setHgap(10);// w w w . j ava2 s . c om gridpane.setVgap(10); ColumnConstraints column1 = new ColumnConstraints(150, 150, Double.MAX_VALUE); ColumnConstraints column2 = new ColumnConstraints(50); ColumnConstraints column3 = new ColumnConstraints(150, 150, Double.MAX_VALUE); column1.setHgrow(Priority.ALWAYS); column3.setHgrow(Priority.ALWAYS); gridpane.getColumnConstraints().addAll(column1, column2, column3); // Candidates label Label candidatesLbl = new Label("Candidates"); GridPane.setHalignment(candidatesLbl, HPos.CENTER); gridpane.add(candidatesLbl, 0, 0); // Heroes label Label heroesLbl = new Label("Letters"); gridpane.add(heroesLbl, 2, 0); GridPane.setHalignment(heroesLbl, HPos.CENTER); final ObservableList<String> candidates = FXCollections.observableArrayList("A", "B", "C", "D"); final ListView<String> candidatesListView = new ListView<>(candidates); gridpane.add(candidatesListView, 0, 1); final ObservableList<String> heroes = FXCollections.observableArrayList(); final ListView<String> heroListView = new ListView<>(heroes); gridpane.add(heroListView, 2, 1); Button sendRightButton = new Button(" > "); sendRightButton.setOnAction((ActionEvent event) -> { String potential = candidatesListView.getSelectionModel().getSelectedItem(); if (potential != null) { candidatesListView.getSelectionModel().clearSelection(); candidates.remove(potential); heroes.add(potential); } }); Button sendLeftButton = new Button(" < "); sendLeftButton.setOnAction((ActionEvent event) -> { String notHero = heroListView.getSelectionModel().getSelectedItem(); if (notHero != null) { heroListView.getSelectionModel().clearSelection(); heroes.remove(notHero); candidates.add(notHero); } }); // place the buttons VBox vbox = new VBox(5); vbox.setAlignment(Pos.CENTER); vbox.getChildren().addAll(sendRightButton, sendLeftButton); GridPane.setHalignment(vbox, HPos.CENTER); gridpane.add(vbox, 1, 1); // place the grid root.setCenter(gridpane); GridPane.setVgrow(root, Priority.ALWAYS); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { final Label label = new Label("Progress:"); final ProgressBar progressBar = new ProgressBar(0); final ProgressIndicator progressIndicator = new ProgressIndicator(0); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final TextArea textArea = new TextArea(); startButton.setOnAction((ActionEvent event) -> { startButton.setDisable(true);/*from w w w .j av a2 s. c o m*/ progressBar.setProgress(0); progressIndicator.setProgress(0); textArea.setText(""); cancelButton.setDisable(false); copyWorker = createWorker(numFiles); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); progressIndicator.progressProperty().unbind(); progressIndicator.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener( (ObservableValue<? extends String> observable, String oldValue, String newValue) -> { textArea.appendText(newValue + "\n"); }); new Thread(copyWorker).start(); }); cancelButton.setOnAction((ActionEvent event) -> { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); progressIndicator.progressProperty().unbind(); progressIndicator.setProgress(0); textArea.appendText("File transfer was cancelled."); }); BorderPane root = new BorderPane(); Scene scene = new Scene(root, 500, 250, javafx.scene.paint.Color.WHITE); FlowPane topPane = new FlowPane(5, 5); topPane.setPadding(new Insets(5)); topPane.setAlignment(Pos.CENTER); topPane.getChildren().addAll(label, progressBar, progressIndicator); GridPane middlePane = new GridPane(); middlePane.setPadding(new Insets(5)); middlePane.setHgap(20); middlePane.setVgap(20); ColumnConstraints column1 = new ColumnConstraints(300, 400, Double.MAX_VALUE); middlePane.getColumnConstraints().addAll(column1); middlePane.setAlignment(Pos.CENTER); middlePane.add(textArea, 0, 0); FlowPane bottomPane = new FlowPane(5, 5); bottomPane.setPadding(new Insets(5)); bottomPane.setAlignment(Pos.CENTER); bottomPane.getChildren().addAll(startButton, cancelButton); root.setTop(topPane); root.setCenter(middlePane); root.setBottom(bottomPane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:uk.co.everywheremusic.viewcontroller.SetupScene.java
private void startSetupWindow(Stage primaryStage) { try {/*from www . j a v a2s . c o m*/ installFolder = new File(".").getCanonicalPath() + Globals.INSTALL_EXT; } catch (IOException ex) { Logger.getLogger(SetupScene.class.getName()).log(Level.SEVERE, null, ex); installFolder = System.getProperty("user.dir") + Globals.INSTALL_EXT; } primaryStage.setTitle(Globals.APP_NAME); grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); column1 = new ColumnConstraints(100, 100, Double.MAX_VALUE); column1.setHgrow(Priority.ALWAYS); column2 = new ColumnConstraints(100, 100, Double.MAX_VALUE); column2.setHgrow(Priority.ALWAYS); column3 = new ColumnConstraints(100, 100, Double.MAX_VALUE); column3.setHgrow(Priority.ALWAYS); column4 = new ColumnConstraints(100, 100, Double.MAX_VALUE); column4.setHgrow(Priority.ALWAYS); grid.getColumnConstraints().addAll(column1, column2, column3, column4); sceneTitle = new Label(Globals.SETUP_FRAME_TITLE); sceneTitle.setId(Globals.CSS_TITLE_ID); sceneTitle.setPrefWidth(Double.MAX_VALUE); sceneTitle.setAlignment(Pos.CENTER); ImageView imageView = null; try { imageView = new ImageView(); String img = new File(Globals.IC_LOGO).toURI().toURL().toString(); imgLogo = new Image(img); imageView.setImage(imgLogo); } catch (MalformedURLException ex) { Logger.getLogger(ServerScene.class.getName()).log(Level.SEVERE, null, ex); } GridPane titlePane = new GridPane(); ColumnConstraints c1 = new ColumnConstraints(50); ColumnConstraints c2 = new ColumnConstraints(400); titlePane.getColumnConstraints().addAll(c1, c2); titlePane.add(imageView, 0, 0); titlePane.add(sceneTitle, 1, 0); titlePane.setAlignment(Pos.CENTER); grid.add(titlePane, 0, 0, 4, 1); lblFolder = new Label(Globals.SETUP_LBL_MUSIC_FOLDER); grid.add(lblFolder, 0, 2, 3, 1); txtFolder = new TextField(); txtFolder.setText("/home/kyle/Music/Test music"); grid.add(txtFolder, 0, 3, 3, 1); btnFolder = new Button(Globals.SETUP_BTN_MUSIC_FOLDER); btnFolder.setPrefWidth(Double.MAX_VALUE); grid.add(btnFolder, 3, 3); final DirectoryChooser dirChooser = new DirectoryChooser(); btnFolder.setOnAction((ActionEvent event) -> { File dir = dirChooser.showDialog(primaryStage); if (dir != null) { txtFolder.setText(dir.getAbsolutePath()); } }); lblPassword = new Label("Choose a password:"); grid.add(lblPassword, 0, 4, 2, 1); lblConfirmPassword = new Label("Confirm your password:"); grid.add(lblConfirmPassword, 2, 4, 2, 1); txtPassword = new PasswordField(); grid.add(txtPassword, 0, 5, 2, 1); txtConfirmPassword = new PasswordField(); grid.add(txtConfirmPassword, 2, 5, 1, 1); textArea = new TextArea(); textArea.setPrefHeight(Double.MAX_VALUE); textArea.setDisable(true); textArea.setWrapText(true); grid.add(textArea, 0, 7, 4, 2); StackPane progressPane = new StackPane(); lblProgress = new Label(Globals.SETUP_LBL_PERCENT); lblProgress.setId(Globals.CSS_PROGBAR_LBL_ID); lblProgress.setVisible(false); progressBar = new ProgressBar(0); progressBar.setPrefWidth(Double.MAX_VALUE); progressBar.setVisible(false); progressPane.getChildren().addAll(progressBar, lblProgress); progressPane.setAlignment(Pos.CENTER_RIGHT); grid.add(progressPane, 0, 11, 3, 1); StackPane buttonPane = new StackPane(); btnInstall = new Button(Globals.SETUP_BTN_INSTALL); btnInstall.setPrefWidth(Double.MAX_VALUE); btnDone = new Button(Globals.SETUP_BTN_DONE); btnDone.setPrefWidth(Double.MAX_VALUE); btnDone.setVisible(false); buttonPane.getChildren().addAll(btnInstall, btnDone); grid.add(buttonPane, 3, 11); btnInstall.setOnAction((ActionEvent event) -> { boolean valid = validateForm(); if (valid) { lblFolder.setDisable(true); txtFolder.setDisable(true); btnFolder.setDisable(true); lblPassword.setDisable(true); txtPassword.setDisable(true); lblConfirmPassword.setDisable(true); txtConfirmPassword.setDisable(true); textArea.setDisable(false); lblProgress.setVisible(true); progressBar.setVisible(true); btnInstall.setDisable(true); musicFolder = txtFolder.getText(); password = txtPassword.getText(); setupWorker = createSetupWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(setupWorker.progressProperty()); setupWorker.messageProperty().addListener( (ObservableValue<? extends String> observable, String oldValue, String newValue) -> { String[] values = newValue.split("\\|"); lblProgress.setText(values[0] + "%"); textArea.appendText(values[1] + "\n"); if (values[1].equals(Globals.SETUP_MSG_DONE)) { btnInstall.setVisible(false); btnDone.setVisible(true); } }); new Thread(setupWorker).start(); } }); btnDone.setOnAction((ActionEvent event) -> { primaryStage.hide(); new ServerScene(installFolder, musicFolder).showWindow(new Stage()); }); try { String imgUrl = new File(Globals.IC_LOGO).toURI().toURL().toString(); javafx.scene.image.Image i = new javafx.scene.image.Image(imgUrl); primaryStage.getIcons().add(i); } catch (MalformedURLException ex) { Logger.getLogger(ServerScene.class.getName()).log(Level.SEVERE, null, ex); } scene = new Scene(grid, 600, 400); primaryStage.setScene(scene); scene.getStylesheets().add(SetupScene.class.getResource(Globals.CSS_FILE).toExternalForm()); // grid.setGridLinesVisible(true); primaryStage.show(); }