Java Code Examples for javafx.scene.layout.VBox#setSpacing()
The following examples show how to use
javafx.scene.layout.VBox#setSpacing() .
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: HtmlWebView.java From Learn-Java-12-Programming with MIT License | 9 votes |
public void start11(Stage primaryStage) { Text txt1 = new Text("What a beautiful music!"); Text txt2 = new Text("If you don't hear music, turn up the volume."); File f = new File("src/main/resources/jb.mp3"); Media m = new Media(f.toURI().toString()); MediaPlayer mp = new MediaPlayer(m); MediaView mv = new MediaView(mp); VBox vb = new VBox(txt1, txt2, mv); vb.setSpacing(20); vb.setAlignment(Pos.CENTER); vb.setPadding(new Insets(10, 10, 10, 10)); Scene scene = new Scene(vb, 350, 100); primaryStage.setScene(scene); primaryStage.setTitle("JavaFX with embedded media player"); primaryStage.onCloseRequestProperty() .setValue(e -> System.out.println("Bye! See you later!")); primaryStage.show(); mp.play(); }
Example 2
Source File: Demo.java From Enzo with Apache License 2.0 | 7 votes |
@Override public void start(Stage stage) { PushButton control = PushButtonBuilder.create() .prefWidth(81) .prefHeight(43) .build(); ToggleButton button = new ToggleButton("Push"); button.setPrefSize(81, 43); button.getStylesheets().add(getClass().getResource("demo.css").toExternalForm()); VBox pane = new VBox(); pane.setSpacing(5); pane.getChildren().setAll(control, button); Scene scene = new Scene(pane); scene.setFill(Color.rgb(208,69,28)); stage.setTitle("JavaFX Custom Control"); stage.setScene(scene); stage.show(); }
Example 3
Source File: ColorPickerApp.java From oim-fx with MIT License | 6 votes |
public Parent createContent() { final ColorPicker colorPicker = new ColorPicker(Color.GREEN); final Label coloredText = new Label("Colors"); Font font = new Font(53); coloredText.setFont(font); final Button coloredButton = new Button("Colored Control"); Color c = colorPicker.getValue(); coloredText.setTextFill(c); coloredButton.setStyle(createRGBString(c)); colorPicker.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { Color newColor = colorPicker.getValue(); coloredText.setTextFill(newColor); coloredButton.setStyle(createRGBString(newColor)); } }); VBox outerVBox = new VBox(coloredText, coloredButton, colorPicker); outerVBox.setAlignment(Pos.CENTER); outerVBox.setSpacing(20); outerVBox.setMaxSize(VBox.USE_PREF_SIZE, VBox.USE_PREF_SIZE); return outerVBox; }
Example 4
Source File: CheckBoxes.java From marathonv5 with Apache License 2.0 | 6 votes |
public CheckBoxes() { VBox vbox = new VBox(); vbox.setSpacing(10); CheckBox cb1 = new CheckBox("Simple checkbox"); CheckBox cb2 = new CheckBox("Three state checkbox"); cb2.setAllowIndeterminate(true); cb2.setIndeterminate(false); CheckBox cb3 = new CheckBox("Disabled"); cb3.setSelected(true); cb3.setDisable(true); vbox.getChildren().add(cb1); vbox.getChildren().add(cb2); vbox.getChildren().add(cb3); getChildren().add(vbox); }
Example 5
Source File: BindingTest.java From bisq with GNU Affero General Public License v3.0 | 6 votes |
@Override public void start(Stage primaryStage) { VBox root = new VBox(); root.setSpacing(20); Label label = new AutoTooltipLabel(); StringProperty txt = new SimpleStringProperty(); txt.set("-"); label.textProperty().bind(txt); Button button = new AutoTooltipButton("count up"); button.setOnAction(e -> txt.set("counter " + counter++)); root.getChildren().addAll(label, button); primaryStage.setScene(new Scene(root, 400, 400)); primaryStage.show(); }
Example 6
Source File: HTMLEditorSample.java From marathonv5 with Apache License 2.0 | 5 votes |
@Override public void start(Stage stage) { stage.setTitle("HTMLEditor Sample"); stage.setWidth(650); stage.setHeight(500); Scene scene = new Scene(new Group()); VBox root = new VBox(); root.setPadding(new Insets(8, 8, 8, 8)); root.setSpacing(5); root.setAlignment(Pos.BOTTOM_LEFT); final HTMLEditor htmlEditor = new HTMLEditor(); htmlEditor.setPrefHeight(245); htmlEditor.setHtmlText(INITIAL_TEXT); final WebView browser = new WebView(); final WebEngine webEngine = browser.getEngine(); ScrollPane scrollPane = new ScrollPane(); scrollPane.getStyleClass().add("noborder-scroll-pane"); scrollPane.setStyle("-fx-background-color: white"); scrollPane.setContent(browser); scrollPane.setFitToWidth(true); scrollPane.setPrefHeight(180); Button showHTMLButton = new Button("Load Content in Browser"); root.setAlignment(Pos.CENTER); showHTMLButton.setOnAction((ActionEvent arg0) -> { webEngine.loadContent(htmlEditor.getHtmlText()); }); root.getChildren().addAll(htmlEditor, showHTMLButton, scrollPane); scene.setRoot(root); stage.setScene(scene); stage.show(); }
Example 7
Source File: MultipleListPane.java From oim-fx with MIT License | 5 votes |
private void initComponent() { StackPane logoStackPane = new StackPane(); logoStackPane.setPadding(new Insets(20, 0, 0, 0)); logoStackPane.getChildren().add(logoImageView); HBox lineHBox = new HBox(); lineHBox.setMinHeight(1); lineHBox.setStyle("-fx-background-color:#ed3a3a;"); textLabel.setStyle("-fx-text-fill:rgba(255, 255, 255, 1);-fx-font-size: 16px;"); HBox textLabelHBox = new HBox(); textLabelHBox.setAlignment(Pos.CENTER); textLabelHBox.getChildren().add(textLabel); loginButton.setText("登录微信"); loginButton.setPrefSize(220, 35); HBox loginButtonHBox = new HBox(); loginButtonHBox.setPadding(new Insets(0, 4, 10, 4)); loginButtonHBox.setAlignment(Pos.CENTER); loginButtonHBox.getChildren().add(loginButton); VBox vBox = new VBox(); vBox.setSpacing(20); vBox.setStyle("-fx-background-color:#26292e;"); vBox.getChildren().add(logoStackPane); vBox.getChildren().add(lineHBox); vBox.getChildren().add(textLabelHBox); vBox.getChildren().add(loginButtonHBox); this.setTop(vBox); this.setCenter(listRooPane); this.setStyle("-fx-background-color:#2e3238;"); }
Example 8
Source File: TakeOfferView.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
private Tuple2<Label, VBox> getTradeInputBox(HBox amountValueBox, String promptText) { Label descriptionLabel = new AutoTooltipLabel(promptText); descriptionLabel.setId("input-description-label"); descriptionLabel.setPrefWidth(170); VBox box = new VBox(); box.setPadding(new Insets(10, 0, 0, 0)); box.setSpacing(2); box.getChildren().addAll(descriptionLabel, amountValueBox); return new Tuple2<>(descriptionLabel, box); }
Example 9
Source File: ProgressSample.java From marathonv5 with Apache License 2.0 | 5 votes |
@Override public void start(Stage stage) { Group root = new Group(); Scene scene = new Scene(root, 300, 250); stage.setScene(scene); stage.setTitle("Progress Controls"); for (int i = 0; i < values.length; i++) { final Label label = labels[i] = new Label(); label.setText("progress:" + values[i]); final ProgressBar pb = pbs[i] = new ProgressBar(); pb.setProgress(values[i]); final ProgressIndicator pin = pins[i] = new ProgressIndicator(); pin.setProgress(values[i]); final HBox hb = hbs[i] = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, pb, pin); } final VBox vb = new VBox(); vb.setSpacing(5); vb.getChildren().addAll(hbs); scene.setRoot(vb); stage.show(); }
Example 10
Source File: ReplayStage.java From dm3270 with Apache License 2.0 | 5 votes |
protected VBox getVBox () { VBox vbox = new VBox (); vbox.setSpacing (15); vbox.setPadding (new Insets (10, 10, 10, 10)); // trbl return vbox; }
Example 11
Source File: PaletteRootPart.java From gef with Eclipse Public License 2.0 | 5 votes |
@Override protected Group createContentLayer() { Group contentLayer = super.createContentLayer(); VBox vbox = new VBox(); vbox.setPickOnBounds(true); // define padding and spacing vbox.setPadding(new Insets(10)); vbox.setSpacing(10d); // fixed at top/right position vbox.setAlignment(Pos.TOP_LEFT); contentLayer.getChildren().add(vbox); return contentLayer; }
Example 12
Source File: HTMLEditorSample.java From marathonv5 with Apache License 2.0 | 4 votes |
public HTMLEditorSample() { final VBox root = new VBox(); root.setPadding(new Insets(8, 8, 8, 8)); root.setSpacing(5); root.setAlignment(Pos.BOTTOM_LEFT); final GridPane grid = new GridPane(); grid.setVgap(5); grid.setHgap(10); final ChoiceBox sendTo = new ChoiceBox(FXCollections.observableArrayList("To:", "Cc:", "Bcc:")); sendTo.setPrefWidth(100); GridPane.setConstraints(sendTo, 0, 0); grid.getChildren().add(sendTo); final TextField tbTo = new TextField(); tbTo.setPrefWidth(400); GridPane.setConstraints(tbTo, 1, 0); grid.getChildren().add(tbTo); final Label subjectLabel = new Label("Subject:"); GridPane.setConstraints(subjectLabel, 0, 1); grid.getChildren().add(subjectLabel); final TextField tbSubject = new TextField(); tbTo.setPrefWidth(400); GridPane.setConstraints(tbSubject, 1, 1); grid.getChildren().add(tbSubject); root.getChildren().add(grid); Platform.runLater(() -> { final HTMLEditor htmlEditor = new HTMLEditor(); htmlEditor.setPrefHeight(370); root.getChildren().addAll(htmlEditor, new Button("Send")); }); final Label htmlLabel = new Label(); htmlLabel.setWrapText(true); getChildren().add(root); }
Example 13
Source File: CheckboxSample.java From marathonv5 with Apache License 2.0 | 4 votes |
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setTitle("Checkbox Sample"); stage.setWidth(250); stage.setHeight(150); rect.setArcHeight(10); rect.setArcWidth(10); rect.setFill(Color.rgb(41, 41, 41)); for (int i = 0; i < names.length; i++) { final Image image = images[i] = new Image(getClass().getResourceAsStream(names[i] + ".png")); final ImageView icon = icons[i] = new ImageView(); final CheckBox cb = cbs[i] = new CheckBox(names[i]); cb.selectedProperty().addListener((ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) -> { icon.setImage(new_val ? image : null); }); } VBox vbox = new VBox(); vbox.getChildren().addAll(cbs); vbox.setSpacing(5); HBox hbox = new HBox(); hbox.getChildren().addAll(icons); hbox.setPadding(new Insets(0, 0, 0, 5)); StackPane stack = new StackPane(); stack.getChildren().add(rect); stack.getChildren().add(hbox); StackPane.setAlignment(rect, Pos.TOP_CENTER); HBox root = new HBox(); root.getChildren().add(vbox); root.getChildren().add(stack); root.setSpacing(40); root.setPadding(new Insets(20, 10, 10, 20)); ((Group) scene.getRoot()).getChildren().add(root); stage.setScene(scene); stage.show(); }
Example 14
Source File: TextAreaDemo.java From JFoenix with Apache License 2.0 | 4 votes |
@Override public void start(Stage stage) { VBox main = new VBox(); main.setSpacing(50); TextArea javafxTextArea = new TextArea(); javafxTextArea.setPromptText("JavaFX Text Area"); main.getChildren().add(javafxTextArea); JFXTextArea jfxTextArea = new JFXTextArea(); jfxTextArea.setPromptText("JFoenix Text Area :D"); jfxTextArea.setLabelFloat(true); RequiredFieldValidator validator = new RequiredFieldValidator(); // NOTE adding error class to text area is causing the cursor to disapper validator.setMessage("Please type something!"); FontIcon warnIcon = new FontIcon(FontAwesomeSolid.EXCLAMATION_TRIANGLE); warnIcon.getStyleClass().add("error"); validator.setIcon(warnIcon); jfxTextArea.getValidators().add(validator); jfxTextArea.focusedProperty().addListener((o, oldVal, newVal) -> { if (!newVal) { jfxTextArea.validate(); } }); main.getChildren().add(jfxTextArea); StackPane pane = new StackPane(); pane.getChildren().add(main); StackPane.setMargin(main, new Insets(100)); pane.setStyle("-fx-background-color:WHITE"); final Scene scene = new Scene(pane, 800, 600); scene.getStylesheets() .add(ButtonDemo.class.getResource("/css/jfoenix-components.css").toExternalForm()); stage.setTitle("JFX Button Demo"); stage.setScene(scene); stage.show(); }
Example 15
Source File: BreakingNewsDemoView.java From htm.java-examples with GNU Affero General Public License v3.0 | 4 votes |
public BreakingNewsDemoView() { setBackground(new Background(new BackgroundFill(Color.WHITE, null, null))); // LeftMargin And RightMargin HBox h = new HBox(); h.prefWidthProperty().bind(widthProperty().divide(20)); h.setFillHeight(true); HBox h2 = new HBox(); h2.prefWidthProperty().bind(widthProperty().divide(20)); h2.setFillHeight(true); // StackPane: Center panel, z:0 CorticalLogoPane, z:1 VBox w/main content StackPane stack = new StackPane(); stack.prefWidthProperty().bind(widthProperty().multiply(9.0/10.0)); stack.prefHeightProperty().bind(heightProperty()); ////////////////////////////// // Z:0 background logo // ////////////////////////////// CorticalLogoBackground backGround = new CorticalLogoBackground(stack); backGround.setOpacity(0.2); ////////////////////////////// // Z:1 Main Content in VBox // ////////////////////////////// VBox vBox = new VBox(); vBox.setSpacing(20); vBox.prefWidthProperty().bind(stack.widthProperty()); vBox.prefHeightProperty().bind(new SimpleDoubleProperty(100.0)); LogoTitlePane header = new LogoTitlePane(); header.setTitleText("Breaking News"); header.setSubTitleText("a Twitter trend tracking demo..."); HBox buttonBar = createSegmentedButtonBar(); DualPanel inputPane = createInputPane(); inputPane.panelHeightProperty().setValue(105); LabelledRadiusPane chartPane = new LabelledRadiusPane("Trend"); chartPane.getChildren().add(createChart(chartPane)); SegmentedButtonBar log = createShowLogButton(vBox); BorderPane logButton = new BorderPane(); logButton.prefWidthProperty().bind(vBox.widthProperty()); logButton.setPrefHeight(10); logButton.setCenter(log); TriplePanel fpDisplay = createFingerprintDisplay(); LabelledRadiusPane loggerPane = createActivityPane(); loggerPane.prefWidthProperty().bind(fpDisplay.widthProperty()); loggerPane.prefHeightProperty().bind(fpDisplay.heightProperty()); RadiusFlipPane flip = new RadiusFlipPane(fpDisplay, loggerPane); fpDisplay.prefWidthProperty().bind(vBox.widthProperty()); flipPaneProperty.set(flip); vBox.getChildren().addAll(header, buttonBar, inputPane, chartPane, logButton, flip); stack.getChildren().addAll(backGround, vBox); // Main Layout: 3 columns, 1 row add(h, 0, 0); add(stack, 1, 0); add(h2, 2, 0); }
Example 16
Source File: TailingReader.java From pikatimer with GNU General Public License v3.0 | 4 votes |
@Override public void showControls(Pane p) { if (displayPane == null) { // initialize our display displayHBox = new HBox(); displayVBox = new VBox(); watchProgressIndicator = new ProgressIndicator(); autoImportToggleSwitch = new ToggleSwitch("Auto-Import File"); autoImportToggleSwitch.selectedProperty().set(false); autoImportToggleSwitch.setPadding(new Insets(3, 0, 0, 0)); // this is a hack to get around a ToggleSwitch bug //autoImportToggleSwitch.setMaxWidth(75); statusLabel = new Label(""); inputButton = new Button("Select File..."); inputTextField = new TextField(); displayVBox.setSpacing(5); //displayVBox.setPadding(new Insets(5, 5, 5, 5)); inputTextField.focusedProperty().addListener((ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue) -> { if (!newPropertyValue && !fileName.getValueSafe().equals(inputTextField.textProperty().getValueSafe())) { // if we are auto-importing, stop that stopReading(); sourceFile = new File(inputTextField.textProperty().getValueSafe()).getAbsoluteFile(); fileName.setValue(sourceFile.getAbsolutePath()); // save the filename timingListener.setAttribute("TailingReader:filename", inputTextField.textProperty().getValueSafe()); // read the file if (!sourceFile.canRead()){ statusLabel.setText("Unable to open file: " + fileName.getValueSafe()); } else readOnce(); } else { System.out.println("No change in file name"); } }); displayHBox.setSpacing(5); displayHBox.setAlignment(Pos.CENTER_LEFT); displayHBox.getChildren().addAll(inputTextField, inputButton, autoImportToggleSwitch, watchProgressIndicator); displayVBox.getChildren().addAll(displayHBox, statusLabel); // Set the action for the inputButton inputButton.setOnAction((event) -> { // Button was clicked, do something... selectInput(); }); watchProgressIndicator.visibleProperty().bind(autoImportToggleSwitch.selectedProperty()); watchProgressIndicator.setProgress(-1.0); // get the current status of the reader //watchProgressIndicator.setPrefHeight(30.0); watchProgressIndicator.setMaxHeight(30.0); autoImportToggleSwitch.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { if(newValue) { System.out.println("TailingReader: autoImportToggleSwitch event: calling startReading()"); startReading(); } else { System.out.println("TailingReader: autoImportToggleSwitch event: calling stopReading()"); stopReading(); } }); autoImportToggleSwitch.selectedProperty().bindBidirectional(readingStatus); inputTextField.textProperty().setValue(fileName.getValueSafe()); // set the action for the inputTextField } // If we were previously visible, clear the old one if (displayPane != null) displayPane.getChildren().clear(); // Now show ourselves.... displayPane = p; displayPane.getChildren().clear(); displayPane.getChildren().add(displayVBox); }
Example 17
Source File: BsqTxView.java From bisq with GNU Affero General Public License v3.0 | 4 votes |
@Override public void initialize() { gridRow = bsqBalanceUtil.addGroup(root, gridRow); tableView = new TableView<>(); tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); addDateColumn(); addTxIdColumn(); addInformationColumn(); addAmountColumn(); addConfidenceColumn(); addTxTypeColumn(); chainSyncIndicator = new JFXProgressBar(); chainSyncIndicator.setPrefWidth(120); if (DevEnv.isDaoActivated()) chainSyncIndicator.setProgress(-1); else chainSyncIndicator.setProgress(0); chainSyncIndicator.setPadding(new Insets(-6, 0, -10, 5)); chainHeightLabel = FormBuilder.addLabel(root, ++gridRow, ""); chainHeightLabel.setId("num-offers"); chainHeightLabel.setPadding(new Insets(-5, 0, -10, 5)); HBox hBox = new HBox(); hBox.setSpacing(10); hBox.getChildren().addAll(chainHeightLabel, chainSyncIndicator); VBox vBox = new VBox(); vBox.setSpacing(10); GridPane.setVgrow(vBox, Priority.ALWAYS); GridPane.setRowIndex(vBox, ++gridRow); GridPane.setColumnSpan(vBox, 3); GridPane.setRowSpan(vBox, 2); GridPane.setMargin(vBox, new Insets(40, -10, 5, -10)); vBox.getChildren().addAll(tableView, hBox); VBox.setVgrow(tableView, Priority.ALWAYS); root.getChildren().add(vBox); walletChainHeightListener = (observable, oldValue, newValue) -> { walletChainHeight = bsqWalletService.getBestChainHeight(); onUpdateAnyChainHeight(); }; }
Example 18
Source File: CreateNewAccount.java From ChatRoomFX with MIT License | 4 votes |
private void showConfirmation(){ Stage stage=new Stage(); VBox box=new VBox(); box.setId("root"); box.setSpacing(10); box.setPadding(new Insets(8)); HBox titleBox=new HBox(); titleBox.setPadding(new Insets(8)); titleBox.setPrefWidth(box.getPrefWidth()); titleBox.setAlignment(Pos.CENTER); Label title=new Label("Set Password"); title.setId("title"); titleBox.getChildren().add(title); box.getChildren().add(titleBox); HBox containerBox=new HBox(); containerBox.setPrefWidth(box.getPrefWidth()); VBox lblBox=new VBox(); lblBox.setSpacing(8); lblBox.setAlignment(Pos.CENTER_LEFT); // lblBox.setPrefWidth(box.getPrefWidth()/3); Label lblPass=new Label("Password"); lblPass.getStyleClass().add("label-info"); Label lblConPass=new Label("Confirm Password"); lblConPass.getStyleClass().add("label-info"); lblBox.getChildren().addAll(lblPass,lblConPass); containerBox.getChildren().add(lblBox); VBox txtBox=new VBox(); txtBox.setSpacing(8); PasswordField txtPass=new PasswordField(); txtPass.setPrefWidth(100); PasswordField txtConPass=new PasswordField(); txtPass.setPrefWidth(100); txtBox.setPadding(new Insets(8)); txtBox.getChildren().addAll(txtPass,txtConPass); containerBox.getChildren().add(txtBox); box.getChildren().add(containerBox); Button button=new Button("Confirm"); button.setId("btnCreate"); button.setOnAction(e->{ if(!txtPass.getText().equals(txtConPass.getText())){ System.out.println("Password mismatch!"); }else{ password=txtPass.getText(); System.out.println("Success!"); ((Stage)txtPass.getScene().getWindow()).close(); } }); HBox buttonBox=new HBox(); buttonBox.setPadding(new Insets(10)); buttonBox.setPrefWidth(box.getPrefWidth()); buttonBox.setAlignment(Pos.CENTER_RIGHT); buttonBox.getChildren().add(button); box.getChildren().add(buttonBox); Scene scene=new Scene(box); scene.getStylesheets().add(getClass().getResource("/lk/ijse/gdse41/publicChatClient/ui/util/css/Login.css").toExternalForm()); stage.setScene(scene); stage.showAndWait(); }
Example 19
Source File: OverrideBehaviorDemo.java From RichTextFX with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void start(Stage primaryStage) { InlineCssTextArea area = new InlineCssTextArea(); InputMap<Event> preventSelectionOrRightArrowNavigation = InputMap.consume( anyOf( // prevent selection via (CTRL + ) SHIFT + [LEFT, UP, DOWN] keyPressed(LEFT, SHIFT_DOWN, SHORTCUT_ANY), keyPressed(KP_LEFT, SHIFT_DOWN, SHORTCUT_ANY), keyPressed(UP, SHIFT_DOWN, SHORTCUT_ANY), keyPressed(KP_UP, SHIFT_DOWN, SHORTCUT_ANY), keyPressed(DOWN, SHIFT_DOWN, SHORTCUT_ANY), keyPressed(KP_DOWN, SHIFT_DOWN, SHORTCUT_ANY), // prevent selection via mouse events eventType(MouseEvent.MOUSE_DRAGGED), eventType(MouseEvent.DRAG_DETECTED), mousePressed().unless(e -> e.getClickCount() == 1 && !e.isShiftDown()), // prevent any right arrow movement, regardless of modifiers keyPressed(RIGHT, SHORTCUT_ANY, SHIFT_ANY), keyPressed(KP_RIGHT, SHORTCUT_ANY, SHIFT_ANY) ) ); Nodes.addInputMap(area, preventSelectionOrRightArrowNavigation); area.replaceText(String.join("\n", "You can't move the caret to the right via the RIGHT arrow key in this area.", "Additionally, you cannot select anything either", "", ":-p" )); area.moveTo(0); CheckBox addExtraEnterHandlerCheckBox = new CheckBox("Temporarily add an EventHandler to area's `onKeyPressedProperty`?"); addExtraEnterHandlerCheckBox.setStyle("-fx-font-weight: bold;"); Label checkBoxExplanation = new Label(String.join("\n", "The added handler will insert a newline character at the caret's position when [Enter] is pressed.", "If checked, the default behavior and added handler will both occur: ", "\tthus, two newline characters should be inserted when user presses [Enter].", "When unchecked, the handler will be removed." )); checkBoxExplanation.setWrapText(true); EventHandler<KeyEvent> insertNewlineChar = e -> { if (e.getCode().equals(ENTER)) { area.insertText(area.getCaretPosition(), "\n"); e.consume(); } }; addExtraEnterHandlerCheckBox.selectedProperty().addListener( (obs, ov, isSelected) -> area.setOnKeyPressed( isSelected ? insertNewlineChar : null) ); VBox vbox = new VBox(area, addExtraEnterHandlerCheckBox, checkBoxExplanation); vbox.setSpacing(10); vbox.setPadding(new Insets(10)); primaryStage.setScene(new Scene(vbox, 700, 350)); primaryStage.show(); primaryStage.setTitle("An area whose behavior has been overridden permanently and temporarily!"); }
Example 20
Source File: SongEntryWindow.java From Quelea with GNU General Public License v3.0 | 4 votes |
/** * Create and initialise the new song window. */ public SongEntryWindow() { initModality(Modality.APPLICATION_MODAL); updateDBOnHide = true; Utils.addIconsToStage(this); confirmButton = new Button(LabelGrabber.INSTANCE.getLabel("add.song.button"), new ImageView(new Image("file:icons/tick.png"))); BorderPane mainPane = new BorderPane(); tabPane = new TabPane(); setupBasicSongPanel(); Tab basicTab = new Tab(LabelGrabber.INSTANCE.getLabel("basic.information.heading")); basicTab.setContent(basicSongPanel); basicTab.setClosable(false); tabPane.getTabs().add(basicTab); setupDetailedSongPanel(); Tab detailedTab = new Tab(LabelGrabber.INSTANCE.getLabel("detailed.info.heading")); detailedTab.setContent(detailedSongPanel); detailedTab.setClosable(false); tabPane.getTabs().add(detailedTab); setupTranslatePanel(); Tab translateTab = new Tab(LabelGrabber.INSTANCE.getLabel("translate.heading")); translateTab.setContent(translatePanel); translateTab.setClosable(false); tabPane.getTabs().add(translateTab); basicSongPanel.getLyricsField().getTextArea().textProperty().addListener((observable, oldValue, newValue) -> { if(!disableTextAreaListeners) { disableTextAreaListeners = true; translatePanel.getDefaultLyricsArea().getTextArea().replaceText(newValue); disableTextAreaListeners = false; } }); translatePanel.getDefaultLyricsArea().getTextArea().textProperty().addListener((observable, oldValue, newValue) -> { if(!disableTextAreaListeners) { disableTextAreaListeners = true; basicSongPanel.getLyricsField().getTextArea().replaceText(newValue); disableTextAreaListeners = false; } }); setupThemePanel(); Tab themeTab = new Tab(LabelGrabber.INSTANCE.getLabel("theme.heading")); themeTab.setContent(themePanel); themeTab.setClosable(false); tabPane.getTabs().add(themeTab); mainPane.setCenter(tabPane); confirmButton.setOnAction(t -> { cancel = false; saveSong(); }); cancelButton = new Button(LabelGrabber.INSTANCE.getLabel("cancel.button"), new ImageView(new Image("file:icons/cross.png"))); cancelButton.setOnAction(t -> { checkSave(); }); addToSchedCBox = new CheckBox(LabelGrabber.INSTANCE.getLabel("add.to.schedule.text")); HBox checkBoxPanel = new HBox(); HBox.setMargin(addToSchedCBox, new Insets(0, 0, 0, 10)); checkBoxPanel.getChildren().add(addToSchedCBox); VBox bottomPanel = new VBox(); bottomPanel.setSpacing(5); HBox buttonPanel = new HBox(); buttonPanel.setSpacing(10); buttonPanel.setAlignment(Pos.CENTER); buttonPanel.getChildren().add(confirmButton); buttonPanel.getChildren().add(cancelButton); bottomPanel.getChildren().add(checkBoxPanel); bottomPanel.getChildren().add(buttonPanel); BorderPane.setMargin(bottomPanel, new Insets(10, 0, 5, 0)); mainPane.setBottom(bottomPanel); setOnShowing(t -> { cancel = true; }); setOnCloseRequest(t -> { checkSave(); }); Scene scene = new Scene(mainPane); if (QueleaProperties.get().getUseDarkTheme()) { scene.getStylesheets().add("org/modena_dark.css"); } setScene(scene); }