Java Code Examples for javafx.scene.control.TextField.setText()

The following are Jave code examples for showing how to use setText() of the javafx.scene.control.TextField class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: FlashLib   File: MainWindow.java   Source Code and License Vote up 6 votes
public VisionControl() {
	slider = new Slider();
	slider.setMin(0.0);
	slider.setMax(255.0);
	slider.setValue(0.0);
	slider.setMaxWidth(350.0);
	slider.setDisable(true);
	
	inputText = new TextField();
	inputText.setText("0");
	inputText.setMaxWidth(50.0);
	inputText.setOnKeyPressed((e)->{
		if(e.getCode() == KeyCode.ENTER){
			setTextFromField();
		}
	});
	inputText.focusedProperty().addListener((obs, o, n)->{
		if(!n.booleanValue()){
			inputText.setText(String.valueOf((int)slider.getValue()));
		}
	});
	
	slider.valueProperty().addListener((obs, o, n)->{
		inputText.setText(String.valueOf((int)slider.getValue()));
	});
	
	nameLabel = new Label("");
	
	HBox top = new HBox();
	top.setSpacing(5.0);
	top.getChildren().addAll(nameLabel, inputText);
	
	VBox all = new VBox();
	all.setSpacing(10.0);
	all.getChildren().addAll(top, slider);
	root = all;
}
 
Example 2
Project: fx-animation-editor   File: TextFieldHelper.java   Source Code and License Vote up 6 votes
public static <T> void bind(TextField textField, ObjectProperty<T> value, StringConverter<T> stringConverter, Runnable onCommit) {
    executeOnFocusLostOrEnter(textField, () -> {
        T oldValue = value.get();
        value.set(stringConverter.fromString(textField.getText()));
        textField.setText(stringConverter.toString(stringConverter.fromString(textField.getText())));
        textField.positionCaret(textField.getLength());
        if (onCommit != null && !Objects.equals(oldValue, value.get())) {
            onCommit.run();
        }
    });
    value.addListener((v, o, n) -> textField.setText(stringConverter.toString(n)));
    textField.setText(stringConverter.toString(value.get()));
}
 
Example 3
Project: fxexperience2   File: GradientSlider.java   Source Code and License Vote up 6 votes
private void incOrDecFieldValue(KeyEvent e, double x) {

        if (!(e.getSource() instanceof TextField)) {
            return; // check it's a textField
        }        // increment or decrement the value
        final TextField tf = (TextField) e.getSource();
        final Double newValue = Double.valueOf(tf.getText()) + x;
        double rounded = round(newValue, roundingFactor);
        slider_slider.setValue(rounded);
        tf.setText(Double.toString(newValue));
        // Avoid using runLater
        // This should be done somewhere else (need to investigate)
//        Platform.runLater(new Runnable() {
//            @Override
//            public void run() {
//                // position caret after new value for easy editing
//                tf.positionCaret(tf.getText().length());
//            }
//        });
    }
 
Example 4
Project: jmonkeybuilder   File: SaveAsEditorDialog.java   Source Code and License Vote up 6 votes
/**
 * Handle the new selected item.
 *
 * @param newValue the new selected item.
 */
@FXThread
protected void processSelection(@Nullable final TreeItem<ResourceElement> newValue) {

    if (newValue != null) {

        final TextField fileNameField = getFileNameField();

        final ResourceElement value = newValue.getValue();
        final Path file = value.getFile();

        if (!Files.isDirectory(file)) {
            fileNameField.setText(FileUtils.getNameWithoutExtension(file));
        }
    }

    validateFileName();
}
 
Example 5
Project: uPMT   File: InterviewTreeViewController.java   Source Code and License Vote up 6 votes
public void renameInter(){
	renameInterview.setDisable(true);
	TextField textField = new TextField();
	textField.setText(interview.getNom());
	textField.setMaxWidth(100);
	textField.requestFocus();
	textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
		 @Override
		    public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue)
		    {
		        if (!newPropertyValue)
		        {
		        	nomEntretien.setText(textField.getText());
		        	interview.setNom(textField.getText());
					interviewPane.setLeft(nomEntretien);
					renameInterview.setDisable(false);
		        }
		    }
	});
	textField.setOnKeyPressed(new EventHandler<KeyEvent>() {

		@Override
		public void handle(KeyEvent event) {
			if(event.getCode() == KeyCode.ENTER){
				nomEntretien.setText(textField.getText());
				interview.setNom(textField.getText());
				interviewPane.setLeft(nomEntretien);
				renameInterview.setDisable(true);
			}
			if(event.getCode() == KeyCode.ESCAPE){
				interviewPane.setLeft(nomEntretien);
				renameInterview.setDisable(true);
			}
		}
	});
	interviewPane.setLeft(textField);
	Platform.runLater(()->textField.requestFocus());
	Platform.runLater(()->textField.selectAll());
	
}
 
Example 6
Project: jmonkeybuilder   File: IntArrayPropertyControl.java   Source Code and License Vote up 6 votes
@Override
@FXThread
protected void reload() {

    final int[] element = getPropertyValue();

    final TextField valueField = getValueField();
    final int caretPosition = valueField.getCaretPosition();

    if (element == null) {
        valueField.setText(StringUtils.EMPTY);
    } else {
        valueField.setText(ArrayUtils.toString(element, " ", false, false));
    }

    valueField.positionCaret(caretPosition);
}
 
Example 7
Project: WebPLP   File: ProgrammerSettingsPanel.java   Source Code and License Vote up 6 votes
private Node maximumChunkSizeSelection( ProgrammerSettingDetails settingDetails )
{
	HBox hBox = new HBox();

	//TODO ensure numerical values only
	Text maxChunkSizeLabel = new Text("Maximum chunk size: ");
	maxChunkSizeLabel.setId(UIConstants.TEXT_COLOR);

	TextField maxChunkSizeTextField = new TextField();
	maxChunkSizeTextField.setText(settingDetails.getMaximumChunkSize());

	maxChunkSizeTextField.textProperty().addListener(( observable, oldValue, newValue ) -> {
		if ( !newValue.isEmpty() )
			UIStyle.applyError(VerifyUtil.simpleIntegerCheck(newValue), maxChunkSizeTextField);
	});

	maximumChunkSizeSelectionModel = maxChunkSizeTextField.textProperty();

	hBox.getChildren().addAll(maxChunkSizeLabel, maxChunkSizeTextField);

	return hBox;
}
 
Example 8
Project: WebPLP   File: ProgrammerSettingsPanel.java   Source Code and License Vote up 6 votes
private Node timeoutSelection( ProgrammerSettingDetails settingDetails )
{
	HBox hBox = new HBox();

	Text receiveTimeoutLabel = new Text("Receive timout (ms): ");
	receiveTimeoutLabel.setId(UIConstants.TEXT_COLOR);

	TextField receiveTimeoutTextField = new TextField();
	receiveTimeoutTextField.setText(settingDetails.getReceiveTimeoutMilliseconds());

	receiveTimeoutTextField.textProperty().addListener(( observable, oldValue, newValue ) -> {
		if ( !newValue.isEmpty() )
			UIStyle.applyError(VerifyUtil.simpleIntegerCheck(newValue), receiveTimeoutTextField);
	});

	receiveTimeoutSelectionModel = receiveTimeoutTextField.textProperty();

	hBox.getChildren().addAll(receiveTimeoutLabel, receiveTimeoutTextField);

	return hBox;
}
 
Example 9
Project: jmonkeybuilder   File: SettingsDialog.java   Source Code and License Vote up 5 votes
/**
 * Process of removing the additional classpath.
 */
@FXThread
private void processRemoveClassesFolder() {
    setClassesFolder(null);

    final TextField textField = getClassesFolderField();
    textField.setText(StringUtils.EMPTY);
}
 
Example 10
Project: marathonv5   File: CheckListFormNode.java   Source Code and License Vote up 5 votes
private VBox createNameField() {
    VBox nameFieldBox = new VBox();
    TextField nameField = new TextField();
    nameField.textProperty().addListener((observable, oldValue, newValue) -> {
        fireContentChanged();
        checkList.setName(nameField.getText());
    });
    nameField.setEditable(mode.isSelectable());
    nameFieldBox.getChildren().addAll(new Label("Name"), nameField);
    HBox.setHgrow(nameField, Priority.ALWAYS);
    VBox.setMargin(nameFieldBox, new Insets(5, 10, 0, 5));
    nameField.setText(checkList.getName());
    HBox.setHgrow(nameFieldBox, Priority.ALWAYS);
    return nameFieldBox;
}
 
Example 11
Project: jedai-ui   File: FileSelectorInput.java   Source Code and License Vote up 5 votes
/**
 * @param parameterValues List of parameters
 * @param index           Index that this input should use to set its value in the parameters list
 * @param windowNode      A Node that will be used for getting the window to show the FileChooser
 * @param defaultValue    (Optional) Path to a previously-selected file for this input
 */
public FileSelectorInput(List<JPair<String, Object>> parameterValues, int index, Node windowNode, String defaultValue) {
    this.setSpacing(5.0);

    TextField fileField = new TextField();
    fileField.textProperty().addListener((observable, oldValue, newValue)
            -> parameterValues.get(index).setRight(newValue));

    Button browseBtn = new Button("Browse");

    // Setup the button action
    FileChooser fileChooser = new FileChooser();
    browseBtn.onActionProperty().setValue(event -> {
        // Open file chooser
        if (previousFolder != null) {
            fileChooser.setInitialDirectory(previousFolder);
        }
        File file = fileChooser.showOpenDialog(windowNode.getScene().getWindow());

        if (file != null) {
            fileField.textProperty().setValue(file.getAbsolutePath());
            // Save the file's directory to remember it if the FileChooser is opened again
            previousFolder = file.getParentFile();
        }
    });

    // Add nodes to HBox
    this.getChildren().addAll(fileField, browseBtn);

    // If there is a default value, use it
    if (!defaultValue.equals("-")) {
        // Set the value to the text field, which will then update the parameterValues list
        fileField.setText(defaultValue);
    }
}
 
Example 12
Project: MooProject   File: HomeTab.java   Source Code and License Vote up 5 votes
public HomeTab(Button button, Pane pane, TextField connectionStatus, TextArea console) {
    super(button, pane);
    this.connectionStatus = connectionStatus;
    this.console = console;

    // set connection status to red, because no connection exists
    connectionStatus.setText(NOT_CONNECTED);
    connectionStatus.setStyle("-fx-text-inner-color: red;");

    // register this as event listener
    EventExecutor.getInstance().register(this);
}
 
Example 13
Project: jmonkeybuilder   File: AlphaInterpolationElement.java   Source Code and License Vote up 5 votes
/**
 * Reload this element.
 */
public void reload() {

    final AlphaInfluencerControl control = getControl();
    final AlphaInfluencer influencer = control.getInfluencer();

    final Float alpha = influencer.getAlpha(getIndex());

    final TextField editableControl = getEditableControl();
    final int caretPosition = editableControl.getCaretPosition();
    editableControl.setText(alpha.toString());
    editableControl.positionCaret(caretPosition);

    super.reload();
}
 
Example 14
Project: jmonkeybuilder   File: SettingsDialog.java   Source Code and License Vote up 5 votes
/**
 * Process of removing the additional envs.
 */
@FXThread
private void processRemoveEF() {
    setAdditionalEnvsFolder(null);

    final TextField textField = getAdditionalEnvsField();
    textField.setText(StringUtils.EMPTY);
}
 
Example 15
Project: Fav-Track   File: loginController.java   Source Code and License Vote up 4 votes
private static void setValues(TextField field, String value){
    if(value!=""){
        field.setText(value);
    }
}
 
Example 16
Project: Fav-Track   File: settingsController.java   Source Code and License Vote up 4 votes
private static void setValues(TextField field, String value){
    if(value!=""){
        field.setText(value);
    }
}
 
Example 17
Project: qiniu   File: Dialogs.java   Source Code and License Vote up 4 votes
public Pair<FileAction, String[]> showFileMovableDialog(String bucket, String key, boolean setKey) {
	MainWindowController main = MainWindowController.getInstance();
	ButtonType ok = new ButtonType(Values.OK, ButtonData.OK_DONE);
	Dialog<String[]> dialog = getDialog(ok);

	TextField keyTextField = new TextField();
	keyTextField.setPrefWidth(300);
	keyTextField.setPromptText(Values.FILE_NAME);
	keyTextField.setText(key);
	ComboBox<String> bucketCombo = new ComboBox<String>();
	bucketCombo.getItems().addAll(main.bucketChoiceCombo.getItems());
	bucketCombo.setValue(bucket);
	CheckBox copyasCheckBox = new CheckBox(Values.COPY_AS);
	copyasCheckBox.setSelected(true);

	GridPane grid = getGridPane();
	grid.add(copyasCheckBox, 0, 0, 2, 1);
	grid.add(new Label(Values.BUCKET_NAME), 0, 1);
	grid.add(bucketCombo, 1, 1);
	if (setKey) {
		grid.add(new Label(Values.FILE_NAME), 0, 2);
		grid.add(keyTextField, 1, 2);
		Platform.runLater(() -> keyTextField.requestFocus());
	}

	dialog.getDialogPane().setContent(grid);
	dialog.setResultConverter(dialogButton -> {
		if (dialogButton == ok) {
			return new String[] { bucketCombo.getValue(), keyTextField.getText() };
		}
		return null;
	});

	Optional<String[]> result = dialog.showAndWait();
	if (result.isPresent()) {
		bucket = bucketCombo.getValue();
		key = keyTextField.getText();
		FileAction action = copyasCheckBox.isSelected() ? FileAction.COPY : FileAction.MOVE;
		return new Pair<FileAction, String[]>(action, new String[] { bucket, key });
	} else {
		return null;
	}
}
 
Example 18
Project: ClusterDeviceControlPlatform   File: ViewUtil.java   Source Code and License Vote up 4 votes
public static Optional<Pair<String, String>> ConnDialogResult() {
        Dialog<Pair<String, String>> dialog = new Dialog<>();
        dialog.setTitle("建立连接");
        dialog.setHeaderText("请输入服务器的连接信息");


        ButtonType loginButtonType = new ButtonType("连接", ButtonBar.ButtonData.OK_DONE);
        dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);

        // Create the username and password labels and fields.
        GridPane grid = new GridPane();
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(20, 150, 10, 10));

        TextField hostName = new TextField();
        hostName.setPromptText("localhost");
        hostName.setText("localhost");
        TextField port = new TextField();
        port.setPromptText("30232");
        port.setText("30232");

        grid.add(new Label("主机名: "), 0, 0);
        grid.add(hostName, 1, 0);
        grid.add(new Label("端口号: "), 0, 1);
        grid.add(port, 1, 1);

        // Enable/Disable login button depending on whether a username was entered.
        //       Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType);
        //  loginButton.setDisable(true);

        // Do some validation (using the Java 8 lambda syntax).
//        hostName.textProperty().addListener((observable, oldValue, newValue) -> {
//            loginButton.setDisable(newValue.trim().isEmpty());
//        });

        dialog.getDialogPane().setContent(grid);

        // Request focus on the username field by default.
        Platform.runLater(() -> hostName.requestFocus());

        dialog.setResultConverter(dialogButton -> {
            if (dialogButton == loginButtonType) {
                return new Pair<>(hostName.getText(), port.getText());
            }
            return null;
        });

        return dialog.showAndWait();
    }
 
Example 19
Project: Balda   File: SceneFormController.java   Source Code and License Vote up 4 votes
@FXML
public void checkWord() {
    Letter letter = getLetter();
    if (letter == null) {
        return;
    }

    // Получаем слово для проверки
    String s = word.getText().trim().toUpperCase();
    if (lines.contains(s)) {
        System.out.println("Нашли слово \"" + s + "\" в словаре");

        if (s.contains(letter.text)) {
            System.out.println("\"" + letter.text + "\" есть в слове \"" + s + "\"");

            boolean[][] used = new boolean[rows][cols];
            char curLetter = letter.text.charAt(0);
            game[letter.row][letter.col] = curLetter;

            boolean found = false;
            for (int r = 0; r < rows && !found; r++) {
                for (int c = 0; c < cols && !found; c++) {
                    // Ищем слово с каждой клеточки
                    if (wordFound(s, 0, r, c, used)) {
                        found = true;
                    }
                }
            }
            if (found) {
                // Получаем клеточку с буквой
                TextField field = gameCells[letter.row][letter.col];
                field.setVisible(false); // Скрываем её
                field.setText(""); // Очищаем текст
                fixedLetter(letter.text.charAt(0), letter.row, letter.col);

                // Расставляем вокруг пустые клеточки если их нет
                addLetterTextFields();
            } else {
                System.out.println("Word not found " + s);
                game[letter.row][letter.col] = ' ';
            }
        }

    } else {
        System.out.println("Не нашли слово \"" + s + "\" в словаре");
    }
}
 
Example 20
Project: karate   File: HeaderPanel.java   Source Code and License Vote up 4 votes
public HeaderPanel(AppSession session) {
    this.session = session;
    content = new HBox(5);
    content.setPadding(new Insets(5));
    setCenter(content);
    textContent = new TextArea();
    textContent.setPrefRowCount(16);
    textContent.setVisible(false);
    setBottom(textContent);
    textContent.setManaged(false);
    textContent.setFont(App.getDefaultFont());
    textContent.focusedProperty().addListener((val, before, after) -> {
        if (!after) { // if we lost focus
            rebuildFeatureIfTextChanged();
        }
    });        
    MenuBar menuBar = new MenuBar();
    Menu fileMenu = new Menu("File");
    openFileMenuItem = new MenuItem("Open");
    fileMenu.getItems().addAll(openFileMenuItem);

    Menu importMenu = new Menu("Import");
    openImportMenuItem = new MenuItem("Open");
    importMenu.getItems().addAll(openImportMenuItem);

    menuBar.getMenus().addAll(fileMenu, importMenu);
    setTop(menuBar);

    if (session != null) {
        Label envLabel = new Label("karate.env");
        envLabel.setPadding(new Insets(5, 0, 0, 0));
        TextField envTextField = new TextField();
        envTextField.setText(session.getEnv().env);
        Button envButton = new Button("Reset");
        envButton.setOnAction(e -> session.resetAll(envTextField.getText()));
        Button runAllButton = new Button("Run ►►");
        runAllButton.setOnAction(e -> session.runAll());            
        Button showContentButton = new Button(getContentButtonText(false));
        initTextContent();
        showContentButton.setOnAction(e -> { 
            boolean visible = !textContent.isVisible();
            textContent.setVisible(visible);
            textContent.setManaged(visible);
            showContentButton.setText(getContentButtonText(visible));
        });
        content.getChildren().addAll(envLabel, envTextField, envButton, runAllButton, showContentButton);            
    }
}