Java Code Examples for javafx.scene.control.ToggleButton#setStyle()
The following examples show how to use
javafx.scene.control.ToggleButton#setStyle() .
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: NavigationTabs.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** Indicate the active tab, notify listeners * @param pressed Button that was pressed */ private void handleTabSelection(final ToggleButton pressed, final boolean notify) { final ObservableList<Node> siblings = buttons.getChildren(); int i = 0, selected_tab = -1; for (Node sibling : siblings) { final ToggleButton button = (ToggleButton) sibling; if (button == pressed) { // If user clicked a button that was already selected, // it would now be de-selected, leaving nothing selected. if (! pressed.isSelected()) { // Re-select! pressed.setSelected(true); } // Highlight active tab by setting it to the 'selected' color pressed.setStyle("-fx-color: " + JFXUtil.webRGB(selected)); selected_tab = i; } else if (button.isSelected()) { // Radio-button behavior: De-select other tabs button.setSelected(false); button.setStyle("-fx-color: " + JFXUtil.webRGB(deselected)); } ++i; } final Listener safe_copy = listener; if (selected_tab >= 0 && notify && safe_copy != null) safe_copy.tabSelected(selected_tab); }
Example 2
Source File: Colors.java From DashboardFx with GNU General Public License v3.0 | 4 votes |
@Override public void initialize(URL location, ResourceBundle resources) { int col = 0; int row = 1; for (MaterialDesign color : MaterialDesign.values()) { String name = color.name().replace("_", " "); String strWeb = ColorHelper.web(color.get()); String strRgb = ColorHelper.rgb(color.get()); String text = String.join("", name, "\n", strWeb, "\n", strRgb); MATCHER.reset(color.name()); String brightness = ""; while (MATCHER.find()) { brightness = MATCHER.group(1).replace("_", " "); } ToggleButton toggle = new ToggleButton( color.name().contains("0") ? "" : color.name() + "\n" + brightness); toggle.setToggleGroup(group); toggle.setAlignment(Pos.CENTER); toggle.setTextFill(Color.WHITE); toggle.setCursor(Cursor.HAND); toggle.setAlignment(Pos.CENTER); toggle.setPrefSize(BOX_WIDTH, BOX_HEIGHT); boolean isBox = false; if(!color.name().contains("0")){ toggle.setMouseTransparent(true); toggle.setStyle("-fx-background-color : white; -fx-text-fill : -gray;" + "-fx-border-color : transparent transparent -light-gray transparent;" + "-fx-background-radius : 0"); toggle.setMinWidth(100D); } else { toggle.setStyle("-fx-background-color : " + formatHexString(color.get()) + ";" + "-fx-background-radius : 0"); isBox = true; } toggle.setOnMousePressed(event -> { String clipboardContent = "Color.web(\"" + strWeb + "\");\n" + "Color." + strRgb + ";"; Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent content = new ClipboardContent(); content.putString(clipboardContent); clipboard.setContent(content); }); boolean finalIsBox = isBox; toggle.setOnMouseEntered(event -> { if(finalIsBox){ toggle.setBackground(new Background(new BackgroundFill(color.get(), new CornerRadii(10), Insets.EMPTY))); toggle.setStyle("-fx-background-radius : 10px; -fx-background-color : " + formatHexString(color.get()) + ";"); } }); toggle.setOnMouseExited(event -> { if(finalIsBox){ toggle.setStyle("-fx-background-radius : 0px; -fx-background-color : " + formatHexString(color.get()) + ";"); } }); Tooltip tooltip = new Tooltip(text); Tooltip.install(toggle, tooltip); grid.add(toggle, col, row); col++; if (row > 16) { if (col == 11) { col = 0; row++; } } else { if (col == 15) { col = 0; row++; } } } grid.setHgap(1); grid.setVgap(1); grid.getRowConstraints().clear(); grid.getColumnConstraints().clear(); }
Example 3
Source File: MetadataOverview.java From sis with Apache License 2.0 | 4 votes |
public MetadataOverview(final DefaultMetadata md, final String fromFile) { this.metadata = md; this.fromFile = fromFile; VBox root = new VBox(); root.setStyle("-fx-background-color: linear-gradient(to bottom right, #aeb7c4, #fafafa);"); // Creation of the differents views. VBox summaryView = createSummaryView(); MetadataNode advancedView = new MetadataNode(md.asTreeTable()); advancedView.setMaxHeight(Double.MAX_VALUE); VBox.setVgrow(advancedView, Priority.ALWAYS); // Create and configure view selection buttons. ToggleGroup buttonGroup = new ToggleGroup(); ToggleButton tb1 = new ToggleButton("Summary"); ToggleButton tb2 = new ToggleButton("Advanced"); tb1.setStyle("-fx-text-fill: white; -fx-font-family: Arial Narrow;-fx-font-weight: bold; -fx-background-color: linear-gradient(#61a2b1, #2A5058); -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 ); -fx-padding: 0.8em;"); tb2.setStyle("-fx-text-fill: white; -fx-font-family: Arial Narrow;-fx-font-weight: bold; -fx-background-color: linear-gradient(#61a2b1, #2A5058); -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 ); -fx-padding: 0.8em;"); tb1.setToggleGroup(buttonGroup); tb1.setSelected(true); tb1.setDisable(true); tb2.setToggleGroup(buttonGroup); buttonGroup.selectToggle(tb1); buttonGroup.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) -> { if (tb2.isSelected()) { tb2.setDisable(true); root.getChildren().remove(summaryView); root.getChildren().add(advancedView); tb1.setDisable(false); } else { tb1.setDisable(true); root.getChildren().add(summaryView); root.getChildren().remove(advancedView); tb2.setDisable(false); } }); HBox toggleGroupLayout = new HBox(); toggleGroupLayout.getChildren().addAll(tb1, tb2); toggleGroupLayout.setPadding(new Insets(0, 0, 10, 0)); root.getChildren().add(toggleGroupLayout); root.getChildren().add(summaryView); this.getChildren().add(root); }