Java Code Examples for javafx.scene.control.TextField#setOnAction()
The following examples show how to use
javafx.scene.control.TextField#setOnAction() .
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: SmartTextFieldListCell.java From pmd-designer with BSD 2-Clause "Simplified" License | 6 votes |
private TextField getEditingGraphic(T t) { Var<String> stringVar = extractEditable(t); final TextField textField = new TextField(stringVar.getValue()); textField.setPromptText(getPrompt()); ControlUtil.makeTextFieldShowPromptEvenIfFocused(textField); // Use onAction here rather than onKeyReleased (with check for Enter), // as otherwise we encounter RT-34685 textField.setOnAction(event -> { stringVar.setValue(textField.getText()); commitEdit(t); event.consume(); }); textField.setOnKeyReleased(ke -> { if (ke.getCode() == KeyCode.ESCAPE) { cancelEdit(); ke.consume(); } }); return textField; }
Example 2
Source File: WebViewContextMenuTest.java From oim-fx with MIT License | 6 votes |
@Override public void start(Stage primaryStage) { TextField locationField = new TextField(START_URL); webView.getEngine().load(START_URL); webView.setContextMenuEnabled(false); createContextMenu(webView); locationField.setOnAction(e -> { webView.getEngine().load(getUrl(locationField.getText())); }); BorderPane root = new BorderPane(webView, locationField, null, null, null); primaryStage.setScene(new Scene(root, 800, 600)); primaryStage.show(); }
Example 3
Source File: AddGem_Controller.java From Path-of-Leveling with MIT License | 6 votes |
private void addAutoCompleteListenerToTextField(TextField whichField, ArrayList<String> autoCompleteContents) { whichField.setOnAction(event -> onEnter(whichField)); JFXAutoCompletePopup<String> autoCompletePopup = new JFXAutoCompletePopup<>(); autoCompletePopup.getSuggestions().addAll(autoCompleteContents); //SelectionHandler sets the value of the comboBox autoCompletePopup.setSelectionHandler(event -> { whichField.setText(event.getObject()); onEnter(whichField); }); whichField.textProperty().addListener((observable, oldVal, newVal) -> { String searchVal = newVal; if (searchVal == null || bTransferringText ) { return; } searchVal = searchVal.trim().toLowerCase(); String finalSearchVal = searchVal; autoCompletePopup.filter(item -> item.toLowerCase().contains(finalSearchVal)); //Hide the autocomplete popup if the filtered suggestions is empty or when the box's original popup is open if (searchVal.isEmpty() || autoCompletePopup.getFilteredSuggestions().isEmpty()) { autoCompletePopup.hide(); } else { autoCompletePopup.show(whichField); } }); }
Example 4
Source File: DownloaderApp.java From FXTutorials with MIT License | 6 votes |
private Parent createContent() { VBox root = new VBox(); root.setPrefSize(400, 600); TextField fieldURL = new TextField(); root.getChildren().addAll(fieldURL); fieldURL.setOnAction(event -> { Task<Void> task = new DownloadTask(fieldURL.getText()); ProgressBar progressBar = new ProgressBar(); progressBar.setPrefWidth(350); progressBar.progressProperty().bind(task.progressProperty()); root.getChildren().add(progressBar); fieldURL.clear(); Thread thread = new Thread(task); thread.setDaemon(true); thread.start(); }); return root; }
Example 5
Source File: View.java From FXTutorials with MIT License | 6 votes |
public View(Controller controller) { this.controller = controller; setPrefSize(635 * 2, 500); Image image = new Image("http://cdn.ndtv.com/tech/windows_10_startmenu_cropped.jpg"); ImageView originalView = new ImageView(image); ImageView modifiedView = new ImageView(); modifiedView.setTranslateX(635); TextField field = new TextField("Enter message"); field.setTranslateY(454); field.setOnAction(e -> controller.onEncode()); Button btnDecode = new Button("DECODE"); btnDecode.setTranslateX(635); btnDecode.setTranslateY(454); btnDecode.setOnAction(e -> controller.onDecode()); controller.injectUI(originalView, modifiedView, field); getChildren().addAll(originalView, modifiedView, field, btnDecode); }
Example 6
Source File: ChatApp.java From FXTutorials with MIT License | 6 votes |
private Parent createContent() { messages.setFont(Font.font(72)); messages.setPrefHeight(550); TextField input = new TextField(); input.setOnAction(event -> { String message = isServer ? "Server: " : "Client: "; message += input.getText(); input.clear(); messages.appendText(message + "\n"); try { connection.send(message); } catch (Exception e) { messages.appendText("Failed to send\n"); } }); VBox root = new VBox(20, messages, input); root.setPrefSize(600, 600); return root; }
Example 7
Source File: CellUtiles.java From phoebus with Eclipse Public License 1.0 | 6 votes |
static <T> TextField createTextField(final Cell<T> cell, final StringConverter<T> converter) { final TextField textField = new TextField(getItemText(cell, converter)); // Use onAction here rather than onKeyReleased (with check for Enter), // as otherwise we encounter RT-34685 textField.setOnAction(event -> { if (converter == null) { throw new IllegalStateException( "Attempting to convert text input into Object, but provided " + "StringConverter is null. Be sure to set a StringConverter " + "in your cell factory."); } cell.commitEdit(converter.fromString(textField.getText())); event.consume(); }); textField.setOnKeyReleased(t -> { if (t.getCode() == KeyCode.ESCAPE) { cell.cancelEdit(); t.consume(); } }); return textField; }
Example 8
Source File: CreatorEditingTableCell.java From tcMenu with Apache License 2.0 | 5 votes |
private void buildEditBox(CreatorProperty prop) { TextField textField = new TextField(prop.getLatestValue()); textField.setMinWidth(this.getWidth() - this.getGraphicTextGap()* 2); textField.focusedProperty().addListener((ObservableValue<? extends Boolean> o, Boolean old, Boolean newVal) -> { if (!newVal) { commitEdit(textField.getText()); } }); textField.setOnAction(actionEvent -> commitEdit(textField.getText())); editorNode = textField; }
Example 9
Source File: Exercise_18_36.java From Intro-to-Java-Programming with MIT License | 5 votes |
@Override // Override the start method in the Application class public void start(Stage primaryStage) { SierpinskiTrianglePane trianglePane = new SierpinskiTrianglePane(); TextField tfOrder = new TextField(); tfOrder.setOnAction( e -> trianglePane.setOrder(Integer.parseInt(tfOrder.getText()))); tfOrder.setPrefColumnCount(4); tfOrder.setAlignment(Pos.BOTTOM_RIGHT); // Pane to hold label, text field, and a button HBox hBox = new HBox(10); hBox.getChildren().addAll(new Label("Enter an order: "), tfOrder); hBox.setAlignment(Pos.CENTER); BorderPane borderPane = new BorderPane(); borderPane.setCenter(trianglePane); borderPane.setBottom(hBox); // Create a scene and place it in the stage Scene scene = new Scene(borderPane, 200, 210); primaryStage.setTitle("Exercise_18_36"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage scene.widthProperty().addListener(ov -> trianglePane.paint()); scene.heightProperty().addListener(ov -> trianglePane.paint()); }
Example 10
Source File: WebViewBrowser.java From netbeans with Apache License 2.0 | 5 votes |
public WebViewPane() { VBox.setVgrow(this, Priority.ALWAYS); setMaxWidth(Double.MAX_VALUE); setMaxHeight(Double.MAX_VALUE); WebView view = new WebView(); view.setMinSize(500, 400); view.setPrefSize(500, 400); final WebEngine eng = view.getEngine(); eng.load("http://www.oracle.com/us/index.html"); final TextField locationField = new TextField("http://www.oracle.com/us/index.html"); locationField.setMaxHeight(Double.MAX_VALUE); Button goButton = new Button("Go"); goButton.setDefaultButton(true); EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { eng.load(locationField.getText().startsWith("http://") ? locationField.getText() : "http://" + locationField.getText()); } }; goButton.setOnAction(goAction); locationField.setOnAction(goAction); eng.locationProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { locationField.setText(newValue); } }); GridPane grid = new GridPane(); grid.setVgap(5); grid.setHgap(5); GridPane.setConstraints(locationField, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES); GridPane.setConstraints(goButton,1,0); GridPane.setConstraints(view, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS); grid.getColumnConstraints().addAll( new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true), new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true) ); grid.getChildren().addAll(locationField, goButton, view); getChildren().add(grid); }
Example 11
Source File: RenamingTextField.java From Recaf with MIT License | 5 votes |
private RenamingTextField(GuiController controller, String initialText, Consumer<RenamingTextField> renameAction) { this.controller = controller; setHideOnEscape(true); setAutoHide(true); setOnShown(e -> { // Center on main window Stage main = controller.windows().getMainWindow().getStage(); int x = (int) (main.getX() + Math.round((main.getWidth() / 2) - (getWidth() / 2))); int y = (int) (main.getY() + Math.round((main.getHeight() / 2) - (getHeight() / 2))); setX(x); setY(y); }); text = new TextField(initialText); text.getStyleClass().add("remap-field"); text.setPrefWidth(400); // Close on hitting escape/close-window bind text.setOnKeyPressed(e -> { if (controller.config().keys().closeWindow.match(e) || e.getCode() == KeyCode.ESCAPE) hide(); }); // Set on-enter action text.setOnAction(e -> renameAction.accept(this)); // Setup & show getScene().setRoot(text); Platform.runLater(() -> { text.requestFocus(); text.selectAll(); }); }
Example 12
Source File: ClearingTextFieldDemo.java From phoebus with Eclipse Public License 1.0 | 5 votes |
@Override public void start(final Stage stage) { final TextField text = new ClearingTextField(); text.setMaxWidth(Double.MAX_VALUE); text.setOnAction(event -> System.out.println("Text is '" + text.getText() + "'")); final BorderPane layout = new BorderPane(text); stage.setScene(new Scene(layout)); stage.show(); }
Example 13
Source File: AdjustbodyMassWidget.java From BowlerStudio with GNU General Public License v3.0 | 4 votes |
public AdjustbodyMassWidget(MobileBase device) { this.device = device; manager = MobileBaseCadManager.get(device); GridPane pane = new GridPane(); TextField mass = new TextField(CreatureLab.getFormatted(device.getMassKg())); mass.setOnAction(event -> { device.setMassKg(textToNum(mass)); if(manager!=null)manager.generateCad(); }); TransformNR currentCentroid = device.getCenterOfMassFromCentroid(); TextField massx = new TextField(CreatureLab.getFormatted(currentCentroid.getX())); massx.setOnAction(event -> { currentCentroid.setX(textToNum(massx)); device.setCenterOfMassFromCentroid(currentCentroid); ; if(manager!=null)manager.generateCad(); }); TextField massy = new TextField(CreatureLab.getFormatted(currentCentroid.getY())); massy.setOnAction(event -> { currentCentroid.setY(textToNum(massy)); device.setCenterOfMassFromCentroid(currentCentroid); ; if(manager!=null)manager.generateCad(); }); TextField massz = new TextField(CreatureLab.getFormatted(currentCentroid.getZ())); massz.setOnAction(event -> { currentCentroid.setZ(textToNum(massz)); device.setCenterOfMassFromCentroid(currentCentroid); ; if(manager!=null)manager.generateCad(); }); pane.add(new Text("Mass"), 0, 0); pane.add(mass, 1, 0); pane.add(new Text("Mass Centroid x"), 0, 1); pane.add(massx, 1, 1); pane.add(new Text("Mass Centroid y"), 0, 2); pane.add(massy, 1, 2); pane.add(new Text("Mass Centroid z"), 0, 3); pane.add(massz, 1,3); getChildren().add(pane); }
Example 14
Source File: DHLinkWidget.java From BowlerStudio with GNU General Public License v3.0 | 4 votes |
public DHLinkWidget(int linkIndex, DHLink dhlink, AbstractKinematicsNR device2, Button del,IOnEngineeringUnitsChange externalListener, MobileBaseCadManager manager ) { this.linkIndex = linkIndex; this.device = device2; if(DHParameterKinematics.class.isInstance(device2)){ dhdevice=(DHParameterKinematics)device2; } this.del = del; AbstractLink abstractLink = device2.getAbstractLink(linkIndex); TextField name = new TextField(abstractLink.getLinkConfiguration().getName()); name.setMaxWidth(100.0); name.setOnAction(event -> { abstractLink.getLinkConfiguration().setName(name.getText()); }); setpoint = new EngineeringUnitsSliderWidget(new IOnEngineeringUnitsChange() { @Override public void onSliderMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) { // TODO Auto-generated method stub } @Override public void onSliderDoneMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) { try { device2.setDesiredJointAxisValue(linkIndex, setpoint.getValue(), 2); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }; } }, abstractLink.getMinEngineeringUnits(), abstractLink.getMaxEngineeringUnits(), device2.getCurrentJointSpaceVector()[linkIndex], 180,dhlink.getLinkType()==DhLinkType.ROTORY?"degrees":"mm"); final Accordion accordion = new Accordion(); if(dhdevice!=null) accordion.getPanes().add(new TitledPane("Configure D-H", new DhSettingsWidget(dhdevice.getChain().getLinks().get(linkIndex),dhdevice,externalListener))); accordion.getPanes().add(new TitledPane("Configure Link", new LinkConfigurationWidget(abstractLink.getLinkConfiguration(), device2.getFactory(),setpoint,manager))); GridPane panel = new GridPane(); panel.getColumnConstraints().add(new ColumnConstraints(80)); // column 1 is 75 wide panel.getColumnConstraints().add(new ColumnConstraints(30)); // column 1 is 75 wide panel.getColumnConstraints().add(new ColumnConstraints(120)); // column 2 is 300 wide panel.add( del, 0, 0); panel.add( new Text("#"+linkIndex), 1, 0); panel.add( name, 2, 0); panel.add( setpoint, 3, 0); panel.add( accordion, 2, 1); getChildren().add(panel); }
Example 15
Source File: LinkSliderWidget.java From BowlerStudio with GNU General Public License v3.0 | 4 votes |
public LinkSliderWidget(int linkIndex, DHLink dhlink, AbstractKinematicsNR d) { this.linkIndex = linkIndex; this.device = d; if (DHParameterKinematics.class.isInstance(device)) { dhdevice = (DHParameterKinematics) device; } abstractLink = device.getAbstractLink(linkIndex); TextField name = new TextField(abstractLink.getLinkConfiguration().getName()); name.setMaxWidth(100.0); name.setOnAction(event -> { abstractLink.getLinkConfiguration().setName(name.getText()); }); setSetpoint(new EngineeringUnitsSliderWidget(this, abstractLink.getMinEngineeringUnits(), abstractLink.getMaxEngineeringUnits(), device.getCurrentJointSpaceVector()[linkIndex], 180, dhlink.getLinkType() == DhLinkType.ROTORY ? "degrees" : "mm")); GridPane panel = new GridPane(); panel.getColumnConstraints().add(new ColumnConstraints(30)); // column 1 // is 75 // wide panel.getColumnConstraints().add(new ColumnConstraints(120)); // column // 1 is // 75 // wide panel.getColumnConstraints().add(new ColumnConstraints(120)); // column // 2 is // 300 // wide panel.add(new Text("#" + linkIndex), 0, 0); panel.add(name, 1, 0); panel.add(getSetpoint(), 2, 0); getChildren().add(panel); abstractLink.addLinkListener(this); // device.addJointSpaceListener(this); }
Example 16
Source File: Exercise_16_15.java From Intro-to-Java-Programming with MIT License | 4 votes |
@Override // Override the start method in the Appliction class public void start(Stage primaryStage) { // Set properties for combobox cbo.getItems().addAll("TOP", "BOTTOM", "LEFT", "RIGHT"); cbo.setStyle("-fx-color: green"); cbo.setValue("LEFT"); // Create a text field TextField tfGap = new TextField("0"); tfGap.setPrefColumnCount(3); // Create a hox to hold labels a text field and combo box HBox paneForSettings = new HBox(10); paneForSettings.setAlignment(Pos.CENTER); paneForSettings.getChildren().addAll(new Label("contentDisplay:"), cbo, new Label("graphicTextGap:"), tfGap); // Create an imageview ImageView image = new ImageView(new Image("image/grapes.gif")); // Label the image Label lblGrapes = new Label("Grapes", image); lblGrapes.setGraphicTextGap(0); // Place the image and its label in a stack pane StackPane paneForImage = new StackPane(lblGrapes); // Create and register handlers cbo.setOnAction(e -> { lblGrapes.setContentDisplay(setDisplay()); }); tfGap.setOnAction(e -> { lblGrapes.setGraphicTextGap(Integer.parseInt(tfGap.getText())); }); // Place nodes in a border pane BorderPane pane = new BorderPane(); pane.setTop(paneForSettings); pane.setCenter(paneForImage); // Create a scene and place it in the stage Scene scene = new Scene(pane, 400, 200); primaryStage.setTitle("Exericse_16_15"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }
Example 17
Source File: SelectedWidgetUITracker.java From phoebus with Eclipse Public License 1.0 | 4 votes |
/** Create an inline editor * * <p>Depending on the widget's properties, it will edit * the PV name or the text. * * @param widget Widget on which to create an inline editor */ private void createInlineEditor(final Widget widget) { // Check for an inline-editable property Optional<WidgetProperty<String>> check; // Defaulting to PV name or text property with some hard-coded exceptions. // Alternative if the list of hard-coded widgets grows: // Add Widget#getInlineEditableProperty() if (widget instanceof ActionButtonWidget) check = Optional.of(((ActionButtonWidget) widget).propText()); else if (widget instanceof GroupWidget) check = Optional.of(((GroupWidget) widget).propName()); else check = widget.checkProperty(CommonWidgetProperties.propPVName); if (! check.isPresent()) check = widget.checkProperty(CommonWidgetProperties.propText); if (! check.isPresent()) return; // Create text field, aligned with widget, but assert minimum size final MacroizedWidgetProperty<String> property = (MacroizedWidgetProperty<String>)check.get(); inline_editor = new TextField(property.getSpecification()); // 'Managed' text field would assume some default size, // but we set the exact size in here inline_editor.setManaged(false); inline_editor.setPromptText(property.getDescription()); // Not really shown since TextField will have focus inline_editor.setTooltip(new Tooltip(property.getDescription())); inline_editor.relocate(tracker.getX(), tracker.getY()); inline_editor.resize(Math.max(100, tracker.getWidth()), Math.max(20, tracker.getHeight())); getChildren().add(inline_editor); // Add autocomplete menu if editing property PVName if (property.getName().equals(CommonWidgetProperties.propPVName.getName())) PVAutocompleteMenu.INSTANCE.attachField(inline_editor); // On enter or lost focus, update the property. On Escape, just close. final ChangeListener<? super Boolean> focused_listener = (prop, old, focused) -> { if (! focused) { if (!property.getSpecification().equals(inline_editor.getText())) undo.execute(new SetMacroizedWidgetPropertyAction(property, inline_editor.getText())); // Close when focus lost closeInlineEditor(); } }; inline_editor.setOnAction(event -> { undo.execute(new SetMacroizedWidgetPropertyAction(property, inline_editor.getText())); inline_editor.focusedProperty().removeListener(focused_listener); closeInlineEditor(); }); inline_editor.setOnKeyPressed(event -> { switch (event.getCode()) { case ESCAPE: event.consume(); inline_editor.focusedProperty().removeListener(focused_listener); closeInlineEditor(); default: } }); inline_editor.focusedProperty().addListener(focused_listener); inline_editor.selectAll(); inline_editor.requestFocus(); }
Example 18
Source File: WebViewBrowser.java From oim-fx with MIT License | 4 votes |
public WebViewPane() { VBox.setVgrow(this, Priority.ALWAYS); setMaxWidth(Double.MAX_VALUE); setMaxHeight(Double.MAX_VALUE); WebView webView = new WebView(); webView.setMinSize(500, 400); webView.setPrefSize(500, 400); final WebEngine webEngine = webView.getEngine(); webEngine.load("http://www.baidu.com"); final TextField locationField = new TextField("http://www.baidu.com"); Button goButton = new Button("Go"); EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { webEngine.load(locationField.getText().startsWith("http://") ? locationField.getText() : "http://" + locationField.getText()); } }; goButton.setDefaultButton(true); goButton.setOnAction(goAction); locationField.setMaxHeight(Double.MAX_VALUE); locationField.setOnAction(goAction); webEngine.locationProperty().addListener(e->{ System.out.println(webEngine.getLocation()); }); webEngine.locationProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { locationField.setText(newValue); } }); WebPage webPage = Accessor.getPageFor(webEngine); webPage.setEditable(true); GridPane grid = new GridPane(); grid.setVgap(5); grid.setHgap(5); GridPane.setConstraints(locationField, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES); GridPane.setConstraints(goButton, 1, 0); GridPane.setConstraints(webView, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS); grid.getColumnConstraints().addAll( new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true), new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true)); grid.getChildren().addAll(locationField, goButton, webView); getChildren().add(grid); }
Example 19
Source File: HelloWebView.java From mars-sim with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage stage) { List<String> args = getParameters().getRaw(); final String initialURL = args.size() > 0 ? args.get(0) : DEFAULT_URL; final WebView webView = new WebView(); final WebEngine webEngine = webView.getEngine(); final TextField urlBox = new TextField(); urlBox.setMinHeight(NAVI_BAR_MIN_DIMENSION); urlBox.setText(initialURL); HBox.setHgrow(urlBox, Priority.ALWAYS); urlBox.setOnAction(e -> webEngine.load(urlBox.getText())); //- Button goButton = new Button("Go"); //- goButton.setOnAction(e -> webEngine.load(urlBox.getText())); final Label bottomTitle = new Label(); bottomTitle.textProperty().bind(urlBox.textProperty()); //- HBox naviBar = new HBox(); //- naviBar.getChildren().addAll(urlBox, goButton); final Button goStopButton = new Button(goButtonUnicodeSymbol); goStopButton.setStyle(buttonStyle); goStopButton.setOnAction(e -> webEngine.load(urlBox.getText())); //- BorderPane root = new BorderPane(); //- root.setTop(naviBar); //- root.setCenter(webView); final Button backButton = new Button(backButtonUnicodeSymbol); backButton.setStyle(buttonStyle); backButton.setDisable(true); backButton.setOnAction(e -> webEngine.getHistory().go(-1)); //- webEngine.locationProperty().addListener((obs, oVal, nVal) //- -> urlBox.setText(nVal)); final Button forwardButton = new Button(forwardButtonUnicodeSymbol); forwardButton.setStyle(buttonStyle); forwardButton.setDisable(true); forwardButton.setOnAction(e -> webEngine.getHistory().go(+1)); final Button reloadButton = new Button(reloadButtonUnicodeSymbol); reloadButton.setStyle(buttonStyle); reloadButton.setOnAction(e -> webEngine.reload()); final HBox naviBar = new HBox(); naviBar.getChildren().addAll(backButton, forwardButton, urlBox, reloadButton, goStopButton); naviBar.setPadding(new Insets(PADDING_VALUE)); // Small padding in the navigation Bar final VBox root = new VBox(); root.getChildren().addAll(naviBar, webView, bottomTitle); VBox.setVgrow(webView, Priority.ALWAYS); webEngine.locationProperty().addListener((observable, oldValue, newValue) -> urlBox.setText(newValue)); // If the Worker.State is in lower State than SUCCEEDED (i.e. in READY, SCHEDULED or RUNNING State), // then the goStopButton should be in 'Stop' configuration // else the goStopButton should be in 'Go' configuration webEngine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> { if (newValue.compareTo(Worker.State.SUCCEEDED) < 0) { bottomTitle.setVisible(true); goStopButton.setText(stopButtonUnicodeSymbol); goStopButton.setOnAction(e -> webEngine.getLoadWorker().cancel()); } else { bottomTitle.setVisible(false); goStopButton.setText(goButtonUnicodeSymbol); goStopButton.setOnAction(e -> webEngine.load(urlBox.getText())); } }); webEngine.getHistory().currentIndexProperty().addListener((observable, oldValue, newValue) -> { int length = webEngine.getHistory().getEntries().size(); backButton.setDisable((int)newValue == 0); forwardButton.setDisable((int)newValue >= length - 1); }); webEngine.load(initialURL); Scene scene = new Scene(root); stage.setScene(scene); //- SimpleStringProperty titleProp = new SimpleStringProperty("HelloWebView: "); SimpleStringProperty titleProp = new SimpleStringProperty("HelloWebView" + " (" + System.getProperty("java.version") + ") : "); stage.titleProperty().bind(titleProp.concat(urlBox.textProperty())); stage.show(); }
Example 20
Source File: TransposedDataSetSample.java From chart-fx with Apache License 2.0 | 4 votes |
@Override public void start(final Stage primaryStage) { // init default 2D Chart final XYChart chart1 = getDefaultChart(); final ErrorDataSetRenderer renderer = (ErrorDataSetRenderer) chart1.getRenderers().get(0); renderer.setAssumeSortedData(false); // necessary to suppress sorted-DataSet-only optimisations // alternate DataSet: // final CosineFunction dataSet1 = new CosineFunction("test cosine", N_SAMPLES); final DataSet dataSet1 = test8Function(0, 4, -1, 3, (Math.PI / N_SAMPLES) * 2 * N_TURNS, 0.2, N_SAMPLES); final TransposedDataSet transposedDataSet1 = TransposedDataSet.transpose(dataSet1, false); renderer.getDatasets().add(transposedDataSet1); // init default 3D Chart with HeatMapRenderer final XYChart chart2 = getDefaultChart(); final ContourDataSetRenderer contourRenderer = new ContourDataSetRenderer(); chart2.getRenderers().setAll(contourRenderer); final DataSet dataSet2 = createTestData(); dataSet2.getAxisDescription(DIM_X).set("x-axis", "x-unit"); dataSet2.getAxisDescription(DIM_Y).set("y-axis", "y-unit"); final TransposedDataSet transposedDataSet2 = TransposedDataSet.transpose(dataSet2, false); contourRenderer.getDatasets().add(transposedDataSet2); // init ToolBar items to illustrate the two different methods to flip the DataSet final CheckBox cbTransposed = new CheckBox("flip data set"); final TextField textPermutation = new TextField("0,1,2"); textPermutation.setPrefWidth(100); cbTransposed.setTooltip(new Tooltip("press to transpose DataSet")); cbTransposed.setGraphic(new Glyph(FONT_AWESOME, FONT_SYMBOL_TRANSPOSE).size(FONT_SIZE)); final Button bApplyPermutation = new Button(null, new Glyph(FONT_AWESOME, FONT_SYMBOL_CHECK).size(FONT_SIZE)); bApplyPermutation.setTooltip(new Tooltip("press to apply permutation")); // flipping method #1: via 'setTransposed(boolean)' - flips only first two axes cbTransposed.setOnAction(evt -> { if (LOGGER.isInfoEnabled()) { LOGGER.atInfo().addArgument(cbTransposed.isSelected()).log("set transpose state to '{}'"); } transposedDataSet1.setTransposed(cbTransposed.isSelected()); transposedDataSet2.setTransposed(cbTransposed.isSelected()); textPermutation.setText(Arrays.stream(transposedDataSet2.getPermutation()).boxed().map(String::valueOf).collect(Collectors.joining(","))); }); // flipping method #2: via 'setPermutation(int[])' - flips arbitrary combination of axes final Runnable permutationAction = () -> { final int[] parsedInt1 = Arrays.asList(textPermutation.getText().split(",")) .subList(0, transposedDataSet1.getDimension()) .stream() .map(String::trim) .mapToInt(Integer::parseInt) .toArray(); final int[] parsedInt2 = Arrays.asList(textPermutation.getText().split(",")) .subList(0, transposedDataSet2.getDimension()) .stream() .map(String::trim) .mapToInt(Integer::parseInt) .toArray(); transposedDataSet1.setPermutation(parsedInt1); transposedDataSet2.setPermutation(parsedInt2); }; textPermutation.setOnAction(evt -> permutationAction.run()); bApplyPermutation.setOnAction(evt -> permutationAction.run()); // the usual JavaFX Application boiler-plate code final ToolBar toolBar = new ToolBar(new Label("method #1 - transpose: "), cbTransposed, new Separator(), new Label("method #2 - permutation: "), textPermutation, bApplyPermutation); final HBox hBox = new HBox(chart1, chart2); VBox.setVgrow(hBox, Priority.ALWAYS); final Scene scene = new Scene(new VBox(toolBar, hBox), 800, 600); primaryStage.setTitle(getClass().getSimpleName()); primaryStage.setScene(scene); primaryStage.show(); primaryStage.setOnCloseRequest(evt -> Platform.exit()); }