List of usage examples for javafx.event EventHandler EventHandler
EventHandler
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Keyboard"); Group root = new Group(); Scene scene = new Scene(root, 530, 300, Color.WHITE); MenuBar menuBar = new MenuBar(); menuBar.prefWidthProperty().bind(primaryStage.widthProperty()); root.getChildren().add(menuBar);/*from w ww.j av a 2s . c om*/ Menu menu = new Menu("File"); menuBar.getMenus().add(menu); MenuItem newItem = MenuItemBuilder.create().text("New") .accelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN)) .onAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { System.out.println("Ctrl-N"); } }).build(); menu.getItems().add(newItem); MenuItem saveItem = MenuItemBuilder.create().text("Save") .accelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN)) .onAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { System.out.println("Ctrl-S"); } }).build(); menu.getItems().add(saveItem); menu.getItems().add(new SeparatorMenuItem()); MenuItem exitItem = MenuItemBuilder.create().text("Exit") .accelerator(new KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN)) .onAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { System.out.println("Ctrl-X"); } }).build(); menu.getItems().add(exitItem); primaryStage.setScene(scene); primaryStage.show(); }
From source file:kz.aksay.polygraph.desktop.DesignerWorkFlow.java
@Override public void start(final Stage primaryStage) { context = kz.aksay.polygraph.util.ContextUtils.getApplicationContext(); context.getBean(UserService.class); acaContext = new AnnotationConfigApplicationContext(); acaContext.setParent(context);/*from ww w.j ava 2 s .c o m*/ acaContext.scan("kz.aksay.polygraph.desktop"); acaContext.refresh(); LoginPane loginPane = acaContext.getBean(LoginPane.class); Scene scene = new Scene(loginPane, 480, 320); scene.getStylesheets().add(DesignerWorkFlow.class.getResource("login.css").toExternalForm()); loginPane.setOnSignInSuccess(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { DirectorPane directorPane = acaContext.getBean(DirectorPane.class); Scene scene = new Scene(directorPane, 640, 480); primaryStage.setScene(scene); } }); primaryStage.setScene(scene); primaryStage.setTitle("JavaFX Welcome"); primaryStage.show(); }
From source file:com.bekwam.mavenpomupdater.AboutDelegate.java
public void init() { if (log.isDebugEnabled()) { log.debug("[INIT] version=" + version); }/*from ww w. j a va 2s. co m*/ Image image = new Image("images/mpu_about.jpg"); imageView.setImage(image); aboutTab.setOnCloseRequest(new EventHandler<Event>() { @Override public void handle(Event arg0) { if (log.isDebugEnabled()) { log.debug("[ABOUT CLOSED]"); } if (tabPane.getTabs().contains(aboutTab)) { tabPane.getTabs().remove(aboutTab); } // needs alt selection here too? arg0.consume(); } }); aboutVersionLabel.setText(version); tabPane.getTabs().remove(aboutTab); // start w/o it showing }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 330, 120, Color.WHITE); BorderPane mainPane = new BorderPane(); root.getChildren().add(mainPane);/*from w ww . ja v a2 s. com*/ final Label label = new Label("Files Transfer:"); final ProgressBar progressBar = new ProgressBar(0); final HBox hb = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, progressBar); mainPane.setTop(hb); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final HBox hb2 = new HBox(); hb2.setSpacing(5); hb2.setAlignment(Pos.CENTER); hb2.getChildren().addAll(startButton, cancelButton); mainPane.setBottom(hb2); startButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(true); progressBar.setProgress(0); cancelButton.setDisable(false); copyWorker = createWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println(newValue); } }); new Thread(copyWorker).start(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); System.out.println("cancelled."); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 330, 120, Color.WHITE); BorderPane mainPane = new BorderPane(); root.getChildren().add(mainPane);// w ww.j a v a 2 s . c o m final Label label = new Label("Files Transfer:"); final ProgressBar progressBar = new ProgressBar(0); final HBox hb = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, progressBar); mainPane.setTop(hb); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final HBox hb2 = new HBox(); hb2.setSpacing(5); hb2.setAlignment(Pos.CENTER); hb2.getChildren().addAll(startButton, cancelButton); mainPane.setBottom(hb2); startButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(true); progressBar.setProgress(0); cancelButton.setDisable(false); copyWorker = createWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println(newValue); } }); new Thread(copyWorker).start(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); System.out.println("cancelled."); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Background Processes"); Group root = new Group(); Scene scene = new Scene(root, 330, 120, Color.WHITE); BorderPane mainPane = new BorderPane(); root.getChildren().add(mainPane);/*from w w w . j av a2 s . c om*/ final Label label = new Label("Files Transfer:"); final ProgressBar progressBar = new ProgressBar(0); final HBox hb = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, progressBar); mainPane.setTop(hb); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final HBox hb2 = new HBox(); hb2.setSpacing(5); hb2.setAlignment(Pos.CENTER); hb2.getChildren().addAll(startButton, cancelButton); mainPane.setBottom(hb2); startButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(true); progressBar.setProgress(0); cancelButton.setDisable(false); copyWorker = createWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println(newValue); } }); new Thread(copyWorker).start(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); System.out.println("cancelled."); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Background Processes"); Group root = new Group(); Scene scene = new Scene(root, 330, 120, Color.WHITE); BorderPane mainPane = new BorderPane(); root.getChildren().add(mainPane);/*from ww w .j av a2s . c o m*/ final Label label = new Label("Files Transfer:"); final ProgressIndicator progressIndicator = new ProgressIndicator(0); final HBox hb = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, progressIndicator); mainPane.setTop(hb); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final HBox hb2 = new HBox(); hb2.setSpacing(5); hb2.setAlignment(Pos.CENTER); hb2.getChildren().addAll(startButton, cancelButton); mainPane.setBottom(hb2); startButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(true); progressIndicator.setProgress(0); cancelButton.setDisable(false); copyWorker = createWorker(); progressIndicator.progressProperty().unbind(); progressIndicator.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println(newValue); } }); new Thread(copyWorker).start(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressIndicator.progressProperty().unbind(); progressIndicator.setProgress(0); System.out.println("cancelled."); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
private void initializeListeners() { // drag from left to right leftListView.setOnDragDetected(new EventHandler<MouseEvent>() { @Override//from w w w .j av a2 s . c om public void handle(MouseEvent event) { if (leftListView.getSelectionModel().getSelectedItem() == null) { return; } Dragboard dragBoard = leftListView.startDragAndDrop(TransferMode.MOVE); ClipboardContent content = new ClipboardContent(); content.putString(leftListView.getSelectionModel().getSelectedItem().getName()); dragBoard.setContent(content); } }); rightListView.setOnDragOver(new EventHandler<DragEvent>() { @Override public void handle(DragEvent dragEvent) { dragEvent.acceptTransferModes(TransferMode.MOVE); } }); rightListView.setOnDragDropped(new EventHandler<DragEvent>() { @Override public void handle(DragEvent dragEvent) { String player = dragEvent.getDragboard().getString(); rightListView.getItems().addAll(new Student(player)); leftList.remove(new Student(player)); leftListView.setItems(leftList); dragEvent.setDropCompleted(true); } }); // drag from right to left rightListView.setOnDragDetected(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { Dragboard dragBoard = rightListView.startDragAndDrop(TransferMode.MOVE); ClipboardContent content = new ClipboardContent(); content.putString(rightListView.getSelectionModel().getSelectedItem().getName()); dragBoard.setContent(content); } }); leftListView.setOnDragOver(new EventHandler<DragEvent>() { @Override public void handle(DragEvent dragEvent) { dragEvent.acceptTransferModes(TransferMode.MOVE); } }); leftListView.setOnDragDropped(new EventHandler<DragEvent>() { @Override public void handle(DragEvent dragEvent) { String player = dragEvent.getDragboard().getString(); leftListView.getItems().remove(new Student(player)); rightList.remove(new Student(player)); dragEvent.setDropCompleted(true); } }); }
From source file:Main.java
private EventHandler<ActionEvent> changeTabPlacement() { return new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { MenuItem mItem = (MenuItem) event.getSource(); String side = mItem.getText(); if ("left".equalsIgnoreCase(side)) { System.out.println("left"); } else if ("right".equalsIgnoreCase(side)) { System.out.println("right"); } else if ("top".equalsIgnoreCase(side)) { System.out.println("top"); } else if ("bottom".equalsIgnoreCase(side)) { System.out.println("bottom"); }//from w w w .j a va2 s. c o m } }; }
From source file:clientechat.TestList.java
@Override public void start(Stage primaryStage) { WebView wv = new WebView(); Button btn = new Button(); TextField textField = new TextField(); VBox vb = new VBox(); WebEngine appendEngine = wv.getEngine(); btn.setOnAction(new EventHandler<ActionEvent>() { @Override//from w w w .j av a 2s .co m public void handle(ActionEvent event) { executejQuery(appendEngine, "$('#content').append(\"<p align=right><b>World!" + escapeHtml(textField.getText()) + "<b><p>\");"); executejQuery(appendEngine, "$(\"html, body\").animate({ scrollTop: $(document).height()-$(window).height() });"); } }); wv.getEngine().loadContent( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" + "<head>\n" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" + "<title>Documento sin ttulo</title>\n" + "</head>\n" + "\n" + "<body id=\"content\">\n" + " \n" + "</body>\n" + "</html>"); vb.getChildren().addAll(wv, btn, textField); Scene scene = new Scene(vb); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); }