Java Code Examples for javafx.scene.control.Button#addEventHandler()
The following examples show how to use
javafx.scene.control.Button#addEventHandler() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomNavigationDrawerSkin.java From WorkbenchFX with Apache License 2.0 | 6 votes |
private Button buildMenuItem(MenuItem item) { Button button = new Button(); button.textProperty().bind(item.textProperty()); button.graphicProperty().bind(item.graphicProperty()); button.disableProperty().bind(item.disableProperty()); button.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); button.getStyleClass().addAll(item.getStyleClass()); button.setOnAction(item.getOnAction()); // Only in cases ALWAYS and SOMETIMES: hide previously hovered button if (!Priority.NEVER.equals(getSkinnable().getMenuHoverBehavior())) { button.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> { // Triggers on hovering over Button if (!isTouchUsed) { if (hoveredBtn != null) { hoveredBtn.hide(); // Hides the previously hovered Button if not null } hoveredBtn = null; // Sets it to null } }); } return button; }
Example 2
Source File: NavigationDrawerSkin.java From WorkbenchFX with Apache License 2.0 | 6 votes |
private Button buildMenuItem(MenuItem item) { Button button = new Button(); button.textProperty().bind(item.textProperty()); button.graphicProperty().bind(item.graphicProperty()); button.disableProperty().bind(item.disableProperty()); button.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); button.getStyleClass().addAll(item.getStyleClass()); button.setOnAction(item.getOnAction()); // Only in cases ALWAYS and SOMETIMES: hide previously hovered button if (!Priority.NEVER.equals(getSkinnable().getMenuHoverBehavior())) { button.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> { // Triggers on hovering over Button if (!isTouchUsed) { if (hoveredBtn != null) { hoveredBtn.hide(); // Hides the previously hovered Button if not null } hoveredBtn = null; // Sets it to null } }); } return button; }
Example 3
Source File: Dialog.java From DashboardFx with GNU General Public License v3.0 | 6 votes |
private static Button createButton(ButtonType type, String text, EventHandler<MouseEvent> eventEventHandler){ Button button = new Button(text); button.setCursor(Cursor.HAND); button.setOnMouseReleased(eventEventHandler); button.setPrefWidth(100); button.addEventHandler(MouseEvent.MOUSE_RELEASED, close); switch (type){ case CANCEL: button.setDefaultButton(true); break; case OK: button.setDefaultButton(true); break; } return button; }
Example 4
Source File: CSSFXTesterApp.java From cssfx with Apache License 2.0 | 6 votes |
private Node createButtonBar() { FlowPane fp = new FlowPane(); fp.getStyleClass().addAll("button-bar", "bottom"); Button gcAction = new Button("Force GC"); gcAction.addEventHandler(ActionEvent.ACTION, e -> { System.out.println("Forcing a GC"); System.gc(); }); Button fakeAction = new Button("Action"); fakeAction.addEventHandler(ActionEvent.ACTION, e -> System.out.println("You clicked the fake action button")); fp.getChildren().addAll(gcAction, fakeAction); String buttonBarCSSUri = getClass().getResource("bottom.css").toExternalForm(); fp.getStylesheets().add(buttonBarCSSUri); return fp; }
Example 5
Source File: TaskBarIcon.java From desktoppanefx with Apache License 2.0 | 5 votes |
public TaskBarIcon(TaskBar taskBar, InternalWindow internalWindow) { this.taskBar = taskBar; this.internalWindow = internalWindow; this.icon = internalWindow.getTitleBar().getIcon(); this.desktopPane = internalWindow.getDesktopPane(); getStyleClass().add("taskbar-icon"); setId(internalWindow.getId()); addEventHandler(MouseEvent.MOUSE_CLICKED, e -> restoreWindow()); HBox pane = new HBox(); pane.setStyle("-fx-alignment:center-left"); pane.setSpacing(10d); pane.setPadding(new Insets(0, 10, 0, 10)); lblTitle = new Label(); lblTitle.textProperty().bind(internalWindow.getTitleBar().titleProperty()); btnClose = new Button("", new FontIcon(MaterialDesign.MDI_WINDOW_CLOSE)); btnClose.visibleProperty().bind(closeVisibleProperty()); btnClose.managedProperty().bind(closeVisibleProperty()); btnClose.disableProperty().bind(disableCloseProperty()); btnClose.getStyleClass().add("taskbar-icon-button"); //Adding the shadow when the mouse cursor is on final DropShadow shadowCloseBtn = new DropShadow(); shadowCloseBtn.setHeight(10d); shadowCloseBtn.setWidth(10d); btnClose.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> btnClose.setEffect(shadowCloseBtn)); //Removing the shadow when the mouse cursor is off btnClose.addEventHandler(MouseEvent.MOUSE_EXITED, e -> btnClose.setEffect(null)); btnClose.addEventHandler(MouseEvent.MOUSE_CLICKED, e -> closeWindow()); pane.getChildren().addAll(icon, lblTitle, btnClose); setContentDisplay(ContentDisplay.GRAPHIC_ONLY); setGraphic(pane); }