@Override public void start(final Stage primaryStage) { Button btn = new Button(); btn.setText("Open Dialog"); btn.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { final Stage dialog = new Stage(); dialog.initModality(Modality.APPLICATION_MODAL); dialog.initOwner(primaryStage); VBox dialogVbox = new VBox(20); dialogVbox.getChildren().add(new Text("This is a Dialog")); Scene dialogScene = new Scene(dialogVbox, 300, 200); dialog.setScene(dialogScene); dialog.show(); } }); }
primaryStage.setTitle("Extension Filter Example"); final Label fileLabel = new Label(); Button btn = new Button("Open FileChooser"); btn.setOnAction(new EventHandler<ActionEvent>() { VBox vBox = new VBox(30); vBox.getChildren().addAll(fileLabel, btn); vBox.setAlignment(Pos.BASELINE_CENTER); primaryStage.setScene(new Scene(root, 300, 250)); primaryStage.show();
final Group root = new Group(); Button button = new Button("Add more windows"); primaryStage.setScene(new Scene(root, 600, 500)); button.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { w.getContentPane().getChildren().add(new Label("Content... \nof the window#"+counter++));
private final Button runButton = new Button("Run"); private final Label label = new Label(); ); runButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { VBox layout = new VBox(10); layout.setPadding(new Insets(10)); layout.setAlignment(Pos.CENTER);
public class AboutBox extends Stage { public AboutBox() throws Exception { initModality(Modality.APPLICATION_MODAL); Button btn = new Button("Close"); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { close(); } }); // Load content via // EITHER Parent root = FXMLLoader.load(getClass().getResource("AboutPage.fxml")); setScene(new Scene(VBoxBuilder.create().children(root, btn).build())); // OR Scene aboutScene = new Scene(VBoxBuilder.create().children(new Text("About me"), btn).alignment(Pos.CENTER).padding(new Insets(10)).build()); setScene(aboutScene); // If your about page is not so complex. no need FXML so its Controller class too. } }
Button startButton = new Button("Start"); startButton.setOnAction(event -> { MessageProducer producer = new MessageProducer(messageQueue); Thread t = new Thread(producer); controls.setPadding(new Insets(10)); controls.setAlignment(Pos.CENTER); primaryStage.setScene(scene); primaryStage.show();
while(!inputFile.exists()) { window = new Stage(); window.initModality(Modality.APPLICATION_MODAL); window.setTitle("File was not found."); window.setMinWidth(250); window.setMaxHeight(100); //form TextField fileInput = new TextField(); Button inputButton = new Button("Upload File"); inputButton.setOnAction(e -> { inputFile = new File(fileInput.getText()); window.close(); }); //Layout VBox layout = new VBox(10); layout.setPadding(new Insets(20, 20, 20, 20)); layout.getChildren().addAll(fileInput, inputButton); //Set scene and show in window. Scene scene = new Scene(layout, 300, 100); window.setScene(scene); window.showAndWait(); }
public void start(Stage primaryStart) throws Exception{ window = primaryStart; window.setTitle("Minesweeper (Eventually)"); //GridPane with 10px padding around edge GridPane grid = new GridPane(); grid.setPadding(new Insets(10, 10, 10, 10)); for(int i = 0; i < 5; i++){ for(int j = 0; j<5; j++){ Button button = new Button("[]"); button.setOnAction(e -> {System.out.println("Something");}); GridPane.setConstraints(button, i,j); grid.getChildren().add(button); } } Scene scene = new Scene(grid, 300, 200); window.setScene(scene); window.show(); }
final Label currentlyPlaying = new Label(); final ProgressBar progress = new ProgressBar(); private ChangeListener<Duration> progressChangeListener; final Button skip = new Button("Skip"); final Button play = new Button("Pause"); skip.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { final MediaPlayer curPlayer = mediaView.getMediaPlayer(); play.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { if ("Pause".equals(play.getText())) { Button invisiblePause = new Button("Pause"); invisiblePause.setVisible(false); play.prefHeightProperty().bind(invisiblePause.heightProperty());
VBox vb = new VBox(); Scene scene = new Scene( vb ); final Dialog dial = new Dialog( title, owner, scene, "res/Confirm.png" ); vb.setPadding( new Inset(10,10,10,10) ); vb.setSpacing( 10 ); Button yesButton = new Button( "Yes" ); yesButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle( ActionEvent e ) { dial.close(); Button noButton = new Button( "No" ); noButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle( ActionEvent e ) { dial.close(); VBox vb = new VBox(); Scene scene = new Scene( vb ); final Dialog dial = new Dialog( title, owner, scene, "res/Info.png" ); vb.setPadding( new Inset(10,10,10,10) ); vb.setSpacing( 10 ); Button okButton = new Button( "OK" ); okButton.setAlignment( Pos.CENTER ); okButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle( ActionEvent e ) { dial.close();
final Label label = new Label(); final Model model = new Model(); final NumberFormat formatter = NumberFormat.getIntegerInstance(); final Button startButton = new Button("Start"); startButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { primaryStage.setScene(scene); primaryStage.show();
private Popup addExitPopup(){ Popup exitPopup = new Popup(); //Exit Panel VBox exitBox = new VBox(); exitBox.setPadding(new Insets(10)); Button exitPaneExit = new Button(); exitPaneExit.setText("Return"); exitPaneExit.setMinSize(75.0, 30.0); exitPaneExit.setOnAction(e -> { exitPopup.hide(); }); Button exitButton = new Button(); exitButton.setText("Exit"); exitButton.setMinSize(75.0, 30.0); exitButton.setOnAction(e -> { System.exit(0); }); exitBox.getChildren().addAll(exitPaneExit,exitButton); exitBox.setVisible(true); exitPopup.setAutoHide(true); exitPopup.getContent().add(exitBox); return exitPopup; }
public class MyPopUp extends Stage { public MyPopUp () { super(); this.setTitle("Pop"); this.setResizable(false); // The important part this.initModality(Modality.APPLICATION_MODAL); BorderPane borderPaneOptionPane = new BorderPane(); borderPaneOptionPane.setCenter(new TextArea()); // For example Button closeButton = new Button("Close"); closeButton.setOnAction(event -> { this.hide(); }); borderPaneOptionPane.setPadding(new Insets(5)); Scene s = new Scene(borderPaneOptionPane); this.setScene(s); }}
long runningTotal = 0; Button plusButton = new Button("+"); Button enterButton = new Button("Enter"); TextField tf = new TextField(); Label displayLabel = new Label(); //Setup you UI here plusButton.setOnAction(event -> { String stringValue = tx.getText(); long value = Long.parseLong(stringValue); runningTotal = runningTotal + value; }); enterButton.setOnAction(event -> { //if you need to remember your last pressed button, you could have done that also, then perform that action here displayLabel.setText("" + runningTotal); });
Button btn = new Button("add new tab"); btn.setOnAction( (e) -> { tabPane.getTabs.add(new Tab("new tab"), new VBox(new Label(Content)) ); });
static class XCell extends ListCell<String> { HBox hbox = new HBox(); Label label = new Label("(empty)"); Pane pane = new Pane(); Button button = new Button("(>)"); String lastItem; hbox.getChildren().addAll(label, pane, button); HBox.setHgrow(pane, Priority.ALWAYS); button.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { StackPane pane = new StackPane(); Scene scene = new Scene(pane, 300, 150); primaryStage.setScene(scene); ObservableList<String> list = FXCollections.observableArrayList( "Item 1", "Item 2", "Item 3", "Item 4"); primaryStage.show();
Button button = new Button("Click the button"); Label l = new Label(); try { List<String> lines = Files.lines(Paths.get("/temp/mantra.txt")) .skip(low) .limit(high - low) .collect(Collectors.toList()); Random rng = new Random(); button.setOnAction(evt -> l.setText(lines.get(rng.nextInt(lines.size())))); } catch (IOException exc) { exc.printStackTrace(); } // ...
VBox vboxForButtons = new VBox(); for(int i=0; i<10; i++){ Button btnNumber = new Button(); btnNumber.setText(String.valueOf(i)); btnNumber.setOnAction((ActionEvent)->{ System.out.println(btnNumber.getText()); }); vboxForButtons.getChildren().add(btnNumber); }
Button btn = new Button(); btn.setText("Toggle boolean flag"); btn.setOnAction(new EventHandler<ActionEvent>() { primaryStage.setScene(new Scene(root, 300, 250)); primaryStage.show();
IntegerProperty property = new SimpleIntegerProperty(); Button btn = new Button("increment"); btn.setOnAction((ActionEvent event) -> { property.set(property.get()+1); }); Label label = new Label(); label.textProperty().bind(property.asString());