import javafx.application.*; import javafx.beans.*; import javafx.beans.property.*; import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.scene.text.*; import javafx.stage.Stage; public class RT18108 extends Application { public static void main(String[] args) { launch(args); } private double h = 0; private double w = 0; private double fSize = 0; private DoubleProperty fSizeV = new SimpleDoubleProperty(); private PasswordField passwordField = new PasswordField(); private TextField textField = new TextField(); private CheckBox checkBox = new CheckBox(); private TextField pasteBox = new TextField(); private Button commitBut = new Button("Commit"); private Button copyBut = new Button("Copy"); private Button cutBut = new Button("Cut"); private Button pasteBut = new Button("Paste"); private Button clearBut = new Button("Clear"); private HBox hbox = new HBox(5.0F); private HBox but1Box = new HBox(5.0F); private HBox but2Box = new HBox(5.0F); private VBox vbox = new VBox(10.0F); Text passwordText; Text passwordText1; private void initBindEvent() { fSizeV.addListener(new InvalidationListener() { public void invalidated(Observable valueModel) { Font font = new Font(fSizeV.getValue()); // passwordField.setFont(font); // textField.setFont(font); checkBox.setFont(font); // pasteBox.setFont(font); commitBut.setFont(font); copyBut.setFont(font); cutBut.setFont(font); pasteBut.setFont(font); clearBut.setFont(font); } }); } @Override public void start(Stage stage) throws Exception { initBindEvent(); h = 300; w = 300; stage = new Stage(); fSize = w / 20; // fire the bind event fSizeV.setValue(fSize); cutBut.setFocusTraversable(false); copyBut.setFocusTraversable(false); passwordField.setText("JavaFX"); passwordField.setPromptText("Enter Text Here"); passwordField.setPrefColumnCount(10); textField.setText("JavaFX"); textField.setPromptText("Enter Text Here"); textField.setPrefColumnCount(10); checkBox.setText("Do for TextField"); checkBox.setSelected(false); pasteBox.setPromptText("Paste Here"); pasteBox.setPrefColumnCount(20); passwordField.textProperty().addListener(new InvalidationListener() { public void invalidated(Observable ov) { passwordText.setText((checkBox.isSelected()) ? ("TextField rawText: " + textField.getText()) : ("Password rawText: " + passwordField.getText())); passwordText1.setText((checkBox.isSelected()) ? ("TextField text: " + textField.getText()) : ("Password text: " + passwordField.getText())); } }); textField.textProperty().addListener(new InvalidationListener() { public void invalidated(Observable ov) { passwordText.setText((checkBox.isSelected()) ? ("TextField rawText: " + textField.getText()) : ("Password rawText: " + passwordField.getText())); passwordText1.setText((checkBox.isSelected()) ? ("TextField text: " + textField.getText()) : ("Password text: " + passwordField.getText())); } }); passwordField.textProperty().addListener(new InvalidationListener() { public void invalidated(Observable ov) { passwordText.setText((checkBox.isSelected()) ? ("TextField rawText: " + textField.getText()) : ("Password rawText: " + passwordField.getText())); passwordText1.setText((checkBox.isSelected()) ? ("TextField text: " + textField.getText()) : ("Password text: " + passwordField.getText())); } }); textField.textProperty().addListener(new InvalidationListener() { public void invalidated(Observable ov) { passwordText.setText((checkBox.isSelected()) ? ("TextField rawText: " + textField.getText()) : ("Password rawText: " + passwordField.getText())); passwordText1.setText((checkBox.isSelected()) ? ("TextField text: " + textField.getText()) : ("Password text: " + passwordField.getText())); } }); commitBut.setOnAction(new EventHandler() { public void handle(ActionEvent t) { try { System.out.println("Width: " + copyBut.getWidth() + ", Height: " + copyBut.getHeight()); if (checkBox.isSelected()) { // textField.commit(); } else { // passwordField.commit(); } } catch (Exception e) { } } }); cutBut.setOnAction(new EventHandler() { public void handle(ActionEvent t) { try { if (checkBox.isSelected()) { System.err.println("textfield cut"); textField.cut(); } else { System.err.println("passwordfield cut"); passwordField.cut(); } } catch (Exception e) { } } }); copyBut.setOnAction(new EventHandler() { public void handle(ActionEvent t) { try { if (checkBox.isSelected()) { textField.copy(); } else { passwordField.copy(); } } catch (Exception e) { } } }); pasteBut.setOnAction(new EventHandler() { public void handle(ActionEvent t) { try { if (checkBox.isSelected()) { textField.paste(); } else { passwordField.paste(); } } catch (Exception e) { } } }); clearBut.setOnAction(new EventHandler() { public void handle(ActionEvent t) { try { if (checkBox.isSelected()) { textField.cut(); } else { passwordField.cut(); } } catch (Exception e) { } } }); hbox.getChildren().clear(); hbox.getChildren().addAll(passwordField, textField); but1Box.getChildren().clear(); but1Box.getChildren().addAll(commitBut, cutBut, copyBut); but2Box.getChildren().clear(); but2Box.getChildren().addAll(pasteBut, clearBut); passwordText = new Text((checkBox.isSelected()) ? ("TextField rawText: " + textField.getText()) : ("Password rawText: " + passwordField.getText())); passwordText1 = new Text((checkBox.isSelected()) ? ("TextField text: " + textField.getText()) : ("Password text: " + passwordField.getText())); vbox.getChildren().clear(); vbox.getChildren().addAll(hbox, checkBox, but1Box, but2Box, pasteBox, passwordText, passwordText1); Scene scene = new Scene(new Group(), w, h); ((Group) scene.getRoot()).getChildren().clear(); ((Group) scene.getRoot()).getChildren().addAll(vbox); passwordField.requestFocus(); stage.setScene(scene); stage.show(); } }