Example usage for javafx.scene.control TextField getText

List of usage examples for javafx.scene.control TextField getText

Introduction

In this page you can find the example usage for javafx.scene.control TextField getText.

Prototype

public final String getText() 

Source Link

Usage

From source file:ambroafb.general.AnnotiationUtils.java

private static Object[] getNodesTypeAndContent(Field field, Object ownerClassObject) {
    Object[] results = new Object[2];
    try {//  w w w.j a v  a 2 s.c om
        boolean accessible = field.isAccessible();
        field.setAccessible(true);

        if (field.getType().equals(TextField.class)
                || field.getType().getSuperclass().equals(NumberField.class)) {
            TextField textField = (TextField) field.get(ownerClassObject);
            results[0] = textField;
            results[1] = textField.getText();
        } else if (field.getType().equals(ADatePicker.class)) {
            ADatePicker datePicker = (ADatePicker) field.get(ownerClassObject);
            results[0] = datePicker;
            results[1] = datePicker.getEditor().getText();
        } else if (field.getType().equals(MapEditor.class)) {
            MapEditor mapEditor = (MapEditor) field.get(ownerClassObject);
            results[0] = mapEditor;
            results[1] = mapEditor.getEditor().getText();
        } else if (field.getType().equals(ImageGalleryController.class)) {
            ImageGalleryController gallery = (ImageGalleryController) field.get(ownerClassObject);
            results[0] = gallery.getRoot();
            results[1] = (gallery.isEmpty()) ? null : "not empty";
        } else if (field.getType().equals(CountComboBox.class)) {
            CountComboBox countComboBox = (CountComboBox) field.get(ownerClassObject);
            results[0] = countComboBox;
            results[1] = (countComboBox.getBasket().isEmpty()) ? null : countComboBox.getValue();
        }
        // Note: ClientComboBox is not ComboBox extened, so this case specific case:
        else if (field.getType().equals(ClientComboBox.class)) {
            ClientComboBox clientComboBox = (ClientComboBox) field.get(ownerClassObject);
            results[0] = clientComboBox;
            results[1] = (clientComboBox.getValue() == null) ? null : clientComboBox.getValue();
        } else if (field.getType().toString().contains("ComboBox")) {
            ComboBox comboBox = (ComboBox) field.get(ownerClassObject);
            results[0] = comboBox;
            // Note: comboBox.getValue() may be null but some class may provides to make some action that avoid nullable and return empty string for example. So we check selection index.
            //                int selectedIndex = comboBox.getSelectionModel().getSelectedIndex();
            //                results[1] = (comboBox.getValue() == null || selectedIndex < 0) ? null : comboBox.getValue();

            results[1] = (comboBox.getValue() == null) ? null : comboBox.getValue();
        }
        field.setAccessible(accessible);
    } catch (IllegalArgumentException | IllegalAccessException ex) {
        Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex);
    }
    return results;
}

From source file:com.anavationllc.o2jb.ConfigurationApp.java

private static void addTextLimiter(final TextField tf, final int maxLength) {
    tf.textProperty().addListener(new ChangeListener<String>() {
        @Override/*from www  . j ava2  s.c  o  m*/
        public void changed(final ObservableValue<? extends String> ov, final String oldValue,
                final String newValue) {
            if (tf.getText().length() > maxLength) {
                String s = tf.getText().substring(0, maxLength);
                tf.setText(s);
            }
        }
    });
}

From source file:de.pixida.logtest.designer.commons.SelectFileButton.java

public static Button createButtonWithFileSelection(final TextField inputFieldShowingPath, final String icon,
        final String title, final String fileMask, final String fileMaskDescription) {
    final Button selectLogFileButton = new Button("Select");
    selectLogFileButton.setGraphic(Icons.getIconGraphics(icon));
    selectLogFileButton.setOnAction(event -> {
        final FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(title);/* w  w w.j a v a 2s . co  m*/
        if (StringUtils.isNotBlank(fileMask) && StringUtils.isNotBlank(fileMaskDescription)) {
            fileChooser.getExtensionFilters()
                    .add(new FileChooser.ExtensionFilter(fileMaskDescription, fileMask));
        }
        File initialDirectory = new File(inputFieldShowingPath.getText().trim());
        if (!initialDirectory.isDirectory()) {
            initialDirectory = initialDirectory.getParentFile();
        }
        if (initialDirectory == null || !initialDirectory.isDirectory()) {
            if (lastFolder != null) {
                initialDirectory = lastFolder;
            } else {
                initialDirectory = new File(".");
            }
        }
        fileChooser.setInitialDirectory(initialDirectory);
        final File selectedFile = fileChooser.showOpenDialog(((Node) event.getTarget()).getScene().getWindow());
        if (selectedFile != null) {
            inputFieldShowingPath.setText(selectedFile.getAbsolutePath());
            final File parent = selectedFile.getParentFile();
            if (parent != null && parent.isDirectory()) {
                lastFolder = parent;
            }
        }
    });
    return selectLogFileButton;
}

From source file:business.Validator.java

/**
 * This method evaluates if the email address field is in fact composed of emails
 * coma separated.//from www. j a  v  a2 s .  com
 * 
 * @param field The text box.
 * @return 
 */
public boolean isEmailAddressFieldValid(TextField field) {
    String s = field.getText().trim();
    // if it is one of the cc or bcc fields, I still wanna evaluate to true.
    if (s.isEmpty())
        return true;
    String[] addresses = s.split(",");

    if (addresses.length > 100)
        return false;

    for (int i = 0; i < addresses.length; i++) {
        if (!isValidEmailAddress(addresses[i].trim()))
            return false;
    }
    return true;
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 150);
    stage.setScene(scene);//from  w w w  . j  a v  a  2s.co  m
    stage.setTitle("Text Field Sample");

    GridPane grid = new GridPane();
    grid.setPadding(new Insets(10, 10, 10, 10));
    grid.setVgap(5);
    grid.setHgap(5);

    scene.setRoot(grid);

    final TextField name = new TextField();
    name.setPromptText("Enter your first name.");
    name.setPrefColumnCount(10);
    name.getText();
    GridPane.setConstraints(name, 0, 0);
    grid.getChildren().add(name);

    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Label nameLbl = new Label("Enter your name:");
    TextField nameFld = new TextField();

    Label msg = new Label();

    Button sayHelloBtn = new Button("Say Hello");

    sayHelloBtn.setOnAction(e -> {//from w w  w  . j  a va2  s  .co m
        String name = nameFld.getText();
        if (name.trim().length() > 0) {
            msg.setText("Hello " + name);
        } else {
            msg.setText("Hello there");
        }
    });

    VBox root = new VBox();

    root.setSpacing(5);

    root.getChildren().addAll(nameLbl, nameFld, msg, sayHelloBtn);

    Scene scene = new Scene(root, 350, 150);
    stage.setScene(scene);
    stage.setTitle("hi");
    stage.show();
}

From source file:mesclasses.controller.PageController.java

public void checkUnique(TextField field) {
    if (!isUnique(field.getText())) {
        addUnicityError(field);/*  ww w .j  a  va  2 s. c  om*/
    } else {
        removeUnicityError(field);
    }
}

From source file:mesclasses.controller.PageController.java

public void checkMandatory(TextField field) {
    if (StringUtils.isBlank(field.getText())) {
        addMissingError(field);/*from   ww  w  .  jav  a  2s.  c  om*/
    } else {
        removeMissingError(field);
    }
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Label nameLbl = new Label("Enter your name:");
    TextField nameFld = new TextField();

    Label msg = new Label();
    msg.setStyle("-fx-text-fill: blue;");

    Button sayHelloBtn = new Button("Say Hello");
    Button exitBtn = new Button("Exit");

    sayHelloBtn.setOnAction(e -> {//from   w w w .jav a2  s.c om
        String name = nameFld.getText();
        if (name.trim().length() > 0) {
            msg.setText("Hello " + name);
        } else {
            msg.setText("Hello there");
        }
    });

    exitBtn.setOnAction(e -> Platform.exit());

    VBox root = new VBox();

    root.setSpacing(5);
    root.getChildren().addAll(nameLbl, nameFld, msg, sayHelloBtn, exitBtn);

    Scene scene = new Scene(root, 350, 150);
    stage.setScene(scene);
    stage.show();
}

From source file:account.management.controller.expenseVoucherController.java

public void calculateTotal() {
    float sum = 0;
    for (int i = 0; i < this.container.getChildren().size(); i++) {
        HBox row = (HBox) this.container.getChildren().get(i);
        TextField amount = (TextField) row.getChildren().get(1);
        if (!amount.getText().equals(""))
            sum += Float.parseFloat(amount.getText());
    }//from   www. j  ava  2  s  .c  o m
    this.total.setText(String.valueOf(sum));
    this.in_word.setText(EnglishNumberToWords.convert((long) sum) + " taka only");
}