public TextFieldEventsCounter(final String counterName) { if (counterName == null) { throw new IllegalArgumentException("Counter name cannot be null."); } try { this.counterName = counterName; Label label = LabelBuilder.create().text(counterName + " : ").prefWidth((new Text(counterName + " : ")).getBoundsInParent().getWidth() + 30).build(); final TextField tf = TextFieldBuilder.create().text("0").prefWidth(50).id(counterName.toUpperCase() + COUNTER_SUFFIX).build(); counter.addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) { log("Counter " + counterName + ": new value : <" + t1 + ">."); tf.setText(t1.toString()); } }); getChildren().addAll(label, tf); } catch (Throwable ex) { log(ex); } }
public StringPropertyValueSetter(Property listeningProperty, BindingType btype, Object testedControl, String initialString) { try { final TextField tf = TextFieldBuilder.create().text(initialString).id(createId(listeningProperty, btype)).build(); this.leadingControl = tf; this.leadingProperty = (Property) tf.textProperty(); this.listeningProperty = listeningProperty; tf.setId(createId(listeningProperty, btype)); propertyValueType = PropertyValueType.STRING; initialValue1 = initialString; bindComponent(btype, testedControl); } catch (Throwable ex) { log(ex); } }
private HBox getListener(String name) { HBox hb = new HBox(); Label label = new Label(name + " : "); TextField tf = TextFieldBuilder.create().id(getListenerTextFieldID(name)).build(); hm.put(name, tf); hb.getChildren().addAll(label, tf); return hb; }
public CustomPopUp(StackPane parentWindow) { super(); this.parent = parentWindow; setMaxHeight(200); setMaxWidth(200); getChildren().add( StackPaneBuilder.create().style(style).minHeight(200).minWidth(200).alignment(Pos.TOP_RIGHT) .children(ButtonBuilder.create().text("Close").onAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent paramT) { parent.getChildren().remove(CustomPopUp.this); } }).build(), TextFieldBuilder.create().translateY(20).build()).build()); }
public CustomPopUp() { super(); getContent().add( StackPaneBuilder.create().style(style).minHeight(200).minWidth(200).alignment(Pos.TOP_RIGHT) .children(ButtonBuilder.create().text("Close").onAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent paramT) { CustomPopUp.this.hide(); } }).build(), TextFieldBuilder.create().translateY(20).build()).build()); }
private void configureScroller() { CustomTextField field = new CustomTextField(); field.setType(CustomTextField.TextFieldType.POSITIVE_INTEGER); field.setPromptText("hello"); field.setMaxCharLength(5); HBox hb1 = HBoxBuilder.create().spacing(10).children(new Label("INTEGER_ONLY : ") ,CustomTextFieldBuilder.create() .type(CustomTextField.TextFieldType.POSITIVE_INTEGER) .maxCharLength(5).build() ).build(); CustomPromptTextField promptField = new CustomPromptTextField(); promptField.setPromptText("Enter value"); vb.getChildren().addAll(HBoxBuilder.create().spacing(10) .children(new Label("POSITIVE_INTEGER : ") ,CustomTextFieldBuilder.create() .type(CustomTextField.TextFieldType.POSITIVE_INTEGER) .maxCharLength(5).build() ).build() ,HBoxBuilder.create().spacing(10) .children(new Label("ALPHABET : ") ,CustomTextFieldBuilder.create() .type(CustomTextField.TextFieldType.ALPHABET) .maxCharLength(5).build() ).build() ,HBoxBuilder.create().spacing(10) .children(new Label("Double : ") ,CustomTextFieldBuilder.create() .type(CustomTextField.TextFieldType.DOUBLE) .maxCharLength(13).build() ).build() ,promptField ,TextFieldBuilder.create().promptText("Enter value").build() ); }
/** * create the UI on first call * * @return */ private Node createUI() { final AnchorPane anchor = AnchorPaneBuilder.create() .styleClass("roundedAnchorPaneFX").build(); final Label heading = LabelBuilder.create() .text(this.getResourceBundle().getString("javafxCompTop")) .alignment(Pos.CENTER).styleClass("propLabel").build(); final Button top = ButtonBuilder.create() .text(this.getResourceBundle().getString("send")).layoutX(120) .onMouseClicked(this.getEventHandler()).alignment(Pos.CENTER) .build(); this.textField = TextFieldBuilder.create().text("") .styleClass("propTextField").alignment(Pos.CENTER).build(); AnchorPane.setBottomAnchor(top, 25.0); AnchorPane.setRightAnchor(top, 25.0); AnchorPane.setRightAnchor(heading, 50.0); AnchorPane.setTopAnchor(heading, 10.0); AnchorPane.setTopAnchor(this.textField, 50.0); AnchorPane.setRightAnchor(this.textField, 25.0); anchor.getChildren().addAll(heading, top, this.textField); GridPane.setHgrow(anchor, Priority.ALWAYS); GridPane.setVgrow(anchor, Priority.ALWAYS); return anchor; }
/** * create the UI on first call * * @return */ private Node createUI() { final AnchorPane anchor = AnchorPaneBuilder.create() .styleClass("roundedAnchorPaneFX").build(); final Label heading = LabelBuilder.create() .text(this.getResourceBundle().getString("javafxComp")) .alignment(Pos.CENTER_RIGHT).styleClass("propLabelBig").build(); final Button left = ButtonBuilder .create() .text(this.getResourceBundle().getString("send")) .layoutX(120) .onMouseClicked( this.getActionListener("id01.id003", "hello stateful component").getListener()) .alignment(Pos.CENTER).build(); this.textField = TextFieldBuilder.create().text("") .styleClass("propTextField").alignment(Pos.CENTER).build(); AnchorPane.setRightAnchor(heading, 25.0); AnchorPane.setTopAnchor(heading, 15.0); AnchorPane.setTopAnchor(left, 80.0); AnchorPane.setRightAnchor(left, 25.0); AnchorPane.setTopAnchor(this.textField, 50.0); AnchorPane.setRightAnchor(this.textField, 25.0); AnchorPane.setLeftAnchor(this.textField, 25.0); anchor.getChildren().addAll(heading, left, this.textField); GridPane.setHgrow(anchor, Priority.ALWAYS); GridPane.setVgrow(anchor, Priority.ALWAYS); return anchor; }
@Override public void start(final Stage stage) throws Exception { final TextField xField = TextFieldBuilder.create().promptText("x").build(); final TextField yField = TextFieldBuilder.create().promptText("y").build(); final TextArea awtField = TextAreaBuilder.create().promptText("awt").build(); final TextArea glassField = TextAreaBuilder.create().promptText("glass").build(); Button act = new Button("Get colors"); act.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { try { int x = Integer.parseInt(xField.getText()); int y = Integer.parseInt(yField.getText()); stage.setX(x + 1); stage.setY(y + 1); java.awt.Robot robotAwt = new java.awt.Robot(); com.sun.glass.ui.Robot robotGlass = new GetAction<com.sun.glass.ui.Robot>() { @Override public void run(Object... os) throws Exception { setResult(com.sun.glass.ui.Application.GetApplication().createRobot()); } }.dispatch(Root.ROOT.getEnvironment()); java.awt.Color glassColor = new java.awt.Color(robotGlass.getPixelColor((int) Math.round(x), (int) Math.round(y))); java.awt.Color awtColor = robotAwt.getPixelColor((int) Math.round(x), (int) Math.round(y)); awtField.setText("AWT robot " + getColorDescription(awtColor)); glassField.setText("Glass robot " + getColorDescription(glassColor)); } catch (Throwable ex) { ex.printStackTrace(); } } }); stage.initStyle(StageStyle.UNDECORATED); stage.setScene(new Scene(new VBox(5, xField, yField, act, awtField, glassField))); stage.show(); }
/** * Creates a {@linkplain DialogService} that displays a * login screen * * @param primaryStage * the primary application {@linkplain Stage} */ public DialogService createLoginDialog(final Stage primaryStage) { final TextField username = TextFieldBuilder.create().promptText( "Username").build(); final PasswordField password = PasswordFieldBuilder.create().promptText( "Password").build(); final Button closeBtn = ButtonBuilder.create().text("Close").build(); final Service<Void> submitService = new Service<Void>() { @Override protected Task<Void> createTask() { return new Task<Void>() { @Override protected Void call() throws Exception { final boolean hasUsername = !username.getText() .isEmpty(); final boolean hasPassword = !password.getText() .isEmpty(); if (hasUsername && hasPassword) { // TODO : perform some sort of authentication here // or you can throw an exception to see the error // message in the dialog window } else { final String invalidFields = (!hasUsername ? username .getPromptText() : "") + ' ' + (!hasPassword ? password.getPromptText() : ""); throw new RuntimeException("Invalid " + invalidFields); } return null; } }; } }; final DialogService dialogService = dialog(primaryStage, "Test Dialog Window", "Please provide a username and password to access the application", null, "Login", 550d, 300d, submitService, closeBtn, username, password); if (closeBtn != null) { closeBtn.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(final MouseEvent event) { dialogService.hide(); } }); } return dialogService; }