@Override protected Parent getRootNode() { return VBoxBuilder.create() .children( ButtonBuilder.create().id("button1").text("Button A").defaultButton(true).build(), ButtonBuilder.create().id("button2").text("Button B").build(), TextFieldBuilder.create().id("text").build()) .build(); }
public BigDecimalFieldSample() { GridPane root = new GridPane(); root.setHgap(10); root.setVgap(10); root.setPadding(new Insets(10, 10, 10, 10)); final BigDecimalField defaultSpinner = new BigDecimalField(); defaultSpinner.getStyleClass().add("bigDecimalField"); final BigDecimalField decimalFormat = new BigDecimalField(BigDecimal.ZERO, new BigDecimal("0.05"), new DecimalFormat("#,##0.00")); decimalFormat.getStyleClass().add("bigDecimalField"); final BigDecimalField percent = new BigDecimalField( BigDecimal.ZERO, new BigDecimal("0.01"), NumberFormat.getPercentInstance()); percent.getStyleClass().add("bigDecimalField"); final BigDecimalField localizedCurrency = new BigDecimalField( BigDecimal.ZERO, new BigDecimal("0.01"), NumberFormat.getCurrencyInstance(Locale.UK)); localizedCurrency.getStyleClass().add("bigDecimalField"); root.addRow(1, new Label("default"), defaultSpinner); root.addRow(2, new Label("custom decimal format"), decimalFormat); root.addRow(3, new Label("percent"), percent); root.addRow(4, new Label("localized currency"), localizedCurrency); root.addRow( 5, new Label("normal TextField"), TextFieldBuilder.create().text("1.000,12").styleClass("bigDecimalField").build()); final ChoiceBox styles = new ChoiceBox( FXCollections.observableArrayList( "rectangular corners - small font", "rounded corners - medium font", "leaf corners - large font")); styles .getSelectionModel() .selectedIndexProperty() .addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> arg0, Number arg1, Number arg2) { System.out.println("index" + arg2.intValue()); Scene scene = styles.getScene(); String pathSquared = BigDecimalFieldSample.class .getResource("BigDecimalField_squared.css") .toExternalForm(); String pathRounded = BigDecimalFieldSample.class .getResource("BigDecimalField_rounded.css") .toExternalForm(); String pathLeaf = BigDecimalFieldSample.class .getResource("BigDecimalField_leaf.css") .toExternalForm(); scene.getStylesheets().removeAll(pathSquared, pathRounded, pathLeaf); if (arg2.intValue() == 0) { scene.getStylesheets().add(pathSquared); } if (arg2.intValue() == 1) { scene.getStylesheets().add(pathRounded); } if (arg2.intValue() == 2) { scene.getStylesheets().add(pathLeaf); } } }); root.addRow(6, new Label("change css"), styles); Button button = new Button("Reset fields"); button.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent arg0) { defaultSpinner.setNumber(new BigDecimal(Math.random() * 1000)); decimalFormat.setNumber(new BigDecimal(Math.random() * 1000)); percent.setNumber(new BigDecimal(Math.random())); localizedCurrency.setNumber(new BigDecimal(Math.random() * 1000)); // disabledField.setNumber(new BigDecimal(Math.random() * 1000)); } }); root.addRow(7, new Label(), button); getChildren().add(root); }