javafx.scene.control.TextField#setText ( )源码实例Demo

下面列出了javafx.scene.control.TextField#setText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mars-sim   文件: Browser.java
public void loadPage(TextField textField, //ProgressBar progressBar,
		WebEngine webEngine, WebView webView) {

	String route = textField.getText();
	if (route !=null)
		if (!route.substring(0, 7).equals("http://")) {
			route = "http://" + route;
			textField.setText(route);
		}

	System.out.println("Loading route: " + route);
	//progressBar.progressProperty().bind(webEngine.getLoadWorker().progressProperty());

	webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
		@Override
		public void changed(ObservableValue<? extends State> value,
				State oldState, State newState) {
			if(newState == State.SUCCEEDED){
				System.out.println("Location loaded + " + webEngine.getLocation());
			}
		}
	});
	webEngine.load(route);


}
 
源代码2 项目: Path-of-Leveling   文件: Preferences_Controller.java
private KeyCombination loadKeybinds(Properties prop, String propertyName, TextField kc_field){
    String loadProp = prop.getProperty(propertyName);
    KeyCombination keyCombination = null;
    //this should load the keybind on the controller but not overwrite
    if(loadProp == null){
        //loadProp = hotkeyDefaults.get(propertyName); <- load default or
        return KeyCombination.NO_MATCH;
    }
    try{
        keyCombination = KeyCombination.keyCombination(loadProp);
        System.out.println("-Preferences- Loaded keybind : " + keyCombination.getName() + " for "+ propertyName);
    }catch(Exception e){
        System.out.println("-Preferences- Loading keybind for "+ propertyName+" failed.");
        keyCombination = KeyCombination.NO_MATCH;
    }
    kc_field.setText(loadProp);
    return keyCombination;
}
 
源代码3 项目: bisq   文件: BsqDashboardView.java
private long updateAveragePriceField(TextField textField, int days, boolean isUSDField) {
    Date pastXDays = getPastDate(days);
    List<TradeStatistics2> bsqTradePastXDays = tradeStatisticsManager.getObservableTradeStatisticsSet().stream()
            .filter(e -> e.getCurrencyCode().equals("BSQ"))
            .filter(e -> e.getTradeDate().after(pastXDays))
            .collect(Collectors.toList());
    List<TradeStatistics2> usdTradePastXDays = tradeStatisticsManager.getObservableTradeStatisticsSet().stream()
            .filter(e -> e.getCurrencyCode().equals("USD"))
            .filter(e -> e.getTradeDate().after(pastXDays))
            .collect(Collectors.toList());
    long average = isUSDField ? getUSDAverage(bsqTradePastXDays, usdTradePastXDays) :
            getBTCAverage(bsqTradePastXDays);
    Price avgPrice = isUSDField ? Price.valueOf("USD", average) :
            Price.valueOf("BSQ", average);
    String avg = FormattingUtils.formatPrice(avgPrice);
    if (isUSDField) {
        textField.setText(avg + " USD/BSQ");
    } else {
        textField.setText(avg + " BSQ/BTC");
    }
    return average;
}
 
public ExtractSubAnimationDialog(@NotNull final NodeTree<?> nodeTree, @NotNull final AnimationTreeNode node) {
    this.nodeTree = nodeTree;
    this.node = node;

    final Animation animation = node.getElement();
    final AnimControl control = notNull(node.getControl());
    final int frameCount = AnimationUtils.getFrameCount(animation);

    final TextField nameField = getNameField();
    nameField.setText(AnimationUtils.findFreeName(control, Messages.MANUAL_EXTRACT_ANIMATION_DIALOG_NAME_EXAMPLE));

    final IntegerTextField startFrameField = getStartFrameField();
    startFrameField.setMinMax(0, frameCount - 2);
    startFrameField.setValue(0);

    final IntegerTextField endFrameField = getEndFrameField();
    endFrameField.setMinMax(1, frameCount - 1);
    endFrameField.setValue(frameCount - 1);
}
 
源代码5 项目: phoenicis   文件: StepRepresentationTextBox.java
@Override
protected void drawStepContent() {
    super.drawStepContent();

    setNextButtonEnabled(false);

    textField = new TextField();
    textField.textProperty().addListener((observable, oldValue, newValue) -> {
        if (StringUtils.isBlank(newValue)) {
            setNextButtonEnabled(false);
        } else {
            setNextButtonEnabled(true);
        }
    });
    textField.setText(defaultValue);
    textField.setLayoutX(10);
    textField.setLayoutY(40);

    this.addToContentPane(textField);
}
 
源代码6 项目: phoebus   文件: LogbooksTagsView.java
/** Sets the field's text based on the selected items list. */
private void setFieldText(ContextMenu dropDown, List<String> selectedItems, TextField field)
{
    // Handle drop down menu item checking.
    for (MenuItem menuItem : dropDown.getItems())
    {
        CustomMenuItem custom = (CustomMenuItem) menuItem;
        CheckBox check = (CheckBox) custom.getContent();
        // If the item is selected make sure it is checked.

        if (selectedItems.contains(check.getText()))
        {
            if (! check.isSelected())
                check.setSelected(true);
        }
        // If the item is not selected, make sure it is not checked.
        else
        {
            if (check.isSelected())
                check.setSelected(false);
        }
    }

    // Build the field text string.
    String fieldText = "";
    for (String item : selectedItems)
    {
        fieldText += (fieldText.isEmpty() ? "" : ", ") + item;
    }

    field.setText(fieldText);
}
 
源代码7 项目: phoebus   文件: CellUtiles.java
static <T> void updateItem(final Cell<T> cell,
                           final StringConverter<T> converter,
                           final HBox hbox,
                           final Node graphic,
                           final TextField textField) {
    if (cell.isEmpty()) {
        cell.setText(null);
        cell.setGraphic(null);
    } else {
        if (cell.isEditing()) {
            if (textField != null) {
                textField.setText(getItemText(cell, converter));
            }
            cell.setText(null);

            if (graphic != null) {
                hbox.getChildren().setAll(graphic, textField);
                cell.setGraphic(hbox);
            } else {
                cell.setGraphic(textField);
            }
        } else {
            cell.setText(getItemText(cell, converter));
            cell.setGraphic(graphic);
        }
    }
}
 
源代码8 项目: Quelea   文件: ImageBackground.java
@Override
public void setThemeForm(ColorPicker backgroundColorPicker, ComboBox<String> backgroundTypeSelect, TextField backgroundImgLocation, TextField backgroundVidLocation, Slider vidHueSlider, CheckBox vidStretchCheckbox) {
    backgroundTypeSelect.getSelectionModel().select(LabelGrabber.INSTANCE.getLabel("image.theme.label"));
    backgroundImgLocation.setText(imageName);
    backgroundColorPicker.setValue(Color.BLACK);
    backgroundColorPicker.fireEvent(new ActionEvent());
    backgroundVidLocation.clear();
    vidHueSlider.setValue(0);
    vidStretchCheckbox.setSelected(false);
}
 
源代码9 项目: pcgen   文件: LocationPanel.java
/**
 * Ask for a path, and return it (possibly return the currentPath.)
 * @param currentPath when entering the method
 * @param dialogTitle to show
 * @param textField to update with the path information
 */
private static void askForPath(final File currentPath, final String dialogTitle, final TextField textField)
{
	GuiAssertions.assertIsJavaFXThread();
	DirectoryChooser directoryChooser = new DirectoryChooser();
	directoryChooser.setInitialDirectory(currentPath);
	directoryChooser.setTitle(dialogTitle);
	File returnFile = directoryChooser.showDialog(null);
	if (returnFile == null)
	{
		returnFile = currentPath;
	}

	textField.setText(returnFile.toString());
}
 
源代码10 项目: AsciidocFX   文件: DialogBuilder.java
public static DialogBuilder newJumpLineDialog() {
    DialogBuilder dialog = new DialogBuilder("", "Goto line/column ");
    dialog.setToolTip("Enter line:column");
    dialog.setKeyReleaseEvent(LINE_COLUMN_REGEX);
    TextField editor = dialog.getEditor();
    editor.setText("0:0");
    editor.selectAll();
    editor.requestFocus();
    return dialog;
}
 
源代码11 项目: marathonv5   文件: BrowserTab.java
protected void addBrowserExeBrowse() {
    String value = BrowserConfig.instance().getValue(getBrowserName(), "browser-exe-path");
    browserExeField = new TextField();
    if (value != null)
        browserExeField.setText(value);
    browseBrowserExeButton = FXUIUtils.createButton("browse", "Select Browser Executable", true, "Browse");
    FileSelectionHandler fileSelectionHandler = new FileSelectionHandler(this, null, null, browseBrowserExeButton,
            "Select Browser executable");
    fileSelectionHandler.setMode(FileSelectionHandler.FILE_CHOOSER);
    browseBrowserExeButton.setOnAction(fileSelectionHandler);
    basicPane.addFormField("Browser Executable:", browserExeField, browseBrowserExeButton);
}
 
源代码12 项目: metastone   文件: IntegerListener.java
@Override
public void changed(ObservableValue<? extends String> observable, String oldText, String newText) {
	if (newText.matches("\\d*")) {
		int value = Integer.parseInt(newText);
		action.onChanged(value);
	} else {
		TextField textField = (TextField) observable;
		textField.setText(oldText);
	}
}
 
源代码13 项目: DashboardFx   文件: ViewerSkin.java
@Override
void mousePressed() {
    TextField textField = getSkinnable();
    shouldMaskText = false;
    textField.setText(textField.getText());
    shouldMaskText = true;
}
 
/**
 * Add new profile/stream name field
 *
 * @param name
 */
protected void addNewProfileStream(String name) {
    waitForNode("#nameTF");
    TextField nameTF = find("#nameTF");
    nameTF.setText(name);
    Button okButton = find("OK");
    clickOn(okButton);
}
 
源代码15 项目: mars-sim   文件: MultiplayerClient.java
public void connectDialog() {

		// Create the custom dialog.
		Dialog<String> dialog = new Dialog<>();
		// Get the Stage.
		Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
/*		
    	stage.setOnCloseRequest(e -> {
			boolean isExit = mainMenu.exitDialog(stage);//.getScreensSwitcher().exitDialog(stage);
			if (!isExit) {
				e.consume();
			}
			else {
				Platform.exit();
			}
		});
*/
		// Add corner icon.
		stage.getIcons().add(new Image(this.getClass().getResource("/icons/network/client48.png").toString()));
		// Add Stage icon
		dialog.setGraphic(new ImageView(this.getClass().getResource("/icons/network/network256.png").toString()));
		// dialog.initOwner(mainMenu.getStage());
		dialog.setTitle("Mars Simulation Project");
		dialog.setHeaderText("Multiplayer Client");
		dialog.setContentText("Enter the host address : ");

		// Set the button types.
		ButtonType connectButtonType = new ButtonType("Connect", ButtonData.OK_DONE);
		// ButtonType localHostButton = new ButtonType("localhost");
		// dialog.getDialogPane().getButtonTypes().addAll(localHostButton,
		// loginButtonType, ButtonType.CANCEL);
		dialog.getDialogPane().getButtonTypes().addAll(connectButtonType, 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 tfUser = new TextField();
		// tfUser.setPromptText("Username");
		TextField tfServerAddress = new TextField();
		// PasswordField password = new PasswordField();
		tfServerAddress.setPromptText("192.168.xxx.xxx");
		tfServerAddress.setText("192.168.xxx.xxx");
		Button localhostB = new Button("Use localhost");

		// grid.add(new Label("Username:"), 0, 0);
		// grid.add(tfUser, 1, 0);
		grid.add(new Label("Server Address:"), 0, 1);
		grid.add(tfServerAddress, 1, 1);
		grid.add(localhostB, 2, 1);

		// Enable/Disable connect button depending on whether the host address
		// was entered.
		Node connectButton = dialog.getDialogPane().lookupButton(connectButtonType);
		connectButton.setDisable(true);

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

		dialog.getDialogPane().setContent(grid);

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

		// Convert the result to a username-password-pair when the login button
		// is clicked.
		dialog.setResultConverter(dialogButton -> {
			if (dialogButton == connectButtonType) {
				return tfServerAddress.getText();
			}
			return null;
		} );

		localhostB.setOnAction(event -> {
			tfServerAddress.setText("127.0.0.1");
		} );
		// localhostB.setPadding(new Insets(1));
		// localhostB.setPrefWidth(10);

		Optional<String> result = dialog.showAndWait();
		result.ifPresent(input -> {
			String serverAddressStr = tfServerAddress.getText();
			this.serverAddressStr = serverAddressStr;
			logger.info("Connecting to server at " + serverAddressStr);
			loginDialog();
		} );

	}
 
源代码16 项目: ClusterDeviceControlPlatform   文件: ViewUtil.java
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();
    }
 
源代码17 项目: mzmine3   文件: FileNameComponent.java
public FileNameComponent(int textfieldcolumns, List<File> lastFiles, FileSelectionType type) {
  // setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));

  this.type = type;

  txtFilename = new TextField();
  txtFilename.setPrefColumnCount(textfieldcolumns);
  txtFilename.setFont(smallFont);

  // last used files chooser button
  // on click - set file name to textField
  btnLastFiles = new LastFilesButton("last", file -> txtFilename.setText(file.getPath()));

  Button btnFileBrowser = new Button("...");
  btnFileBrowser.setOnAction(e -> {
    // Create chooser.
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Select file");

    // Set current directory.
    final String currentPath = txtFilename.getText();
    if (currentPath.length() > 0) {

      final File currentFile = new File(currentPath);
      final File currentDir = currentFile.getParentFile();
      if (currentDir != null && currentDir.exists()) {
        fileChooser.setInitialDirectory(currentDir);
      }
    }

    // Open chooser.
    File selectedFile = null;
    if(type == FileSelectionType.OPEN)
      selectedFile = fileChooser.showOpenDialog(null);
    else
      selectedFile = fileChooser.showSaveDialog(null);
    
    if (selectedFile == null)
      return;
    txtFilename.setText(selectedFile.getPath());
  });

  getChildren().addAll(txtFilename, btnLastFiles, btnFileBrowser);

  setLastFiles(lastFiles);
}
 
源代码18 项目: chart-fx   文件: EditAxis.java
private final TextField getBoundField(final Axis axis, final boolean isLowerBound) {
    final TextField textField = new TextField();

    // ValidationSupport has a slow memory leak
    // final ValidationSupport support = new ValidationSupport();
    // final Validator<String> validator = (final Control control, final
    // String value) -> {
    // boolean condition = value == null ? true :
    // !value.matches(NUMBER_REGEX);
    //
    // // additional check in case of logarithmic axis
    // if (!condition && axis.isLogAxis() && Double.parseDouble(value)
    // <= 0) {
    // condition = true;
    // }
    // // change text colour depending on validity as a number
    // textField.setStyle(condition ? "-fx-text-inner-color: red;" :
    // "-fx-text-inner-color: black;");
    // return ValidationResult.fromMessageIf(control, "not a number",
    // Severity.ERROR, condition);
    // };
    // support.registerValidator(textField, true, validator);

    final Runnable lambda = () -> {
        final double value;
        final boolean isInverted = axis.isInvertedAxis();
        if (isLowerBound) {
            value = isInverted ? axis.getMax() : axis.getMin();
        } else {
            value = isInverted ? axis.getMin() : axis.getMax();
        }
        textField.setText(Double.toString(value));
    };

    axis.invertAxisProperty().addListener((ch, o, n) -> lambda.run());
    axis.minProperty().addListener((ch, o, n) -> lambda.run());
    axis.maxProperty().addListener((ch, o, n) -> lambda.run());

    // force the field to be numeric only
    textField.textProperty().addListener((observable, oldValue, newValue) -> {
        if ((newValue != null) && !newValue.matches("\\d*")) {
            final double val;
            try {
                val = Double.parseDouble(newValue);
            } catch (NullPointerException | NumberFormatException e) {
                // not a parsable number
                textField.setText(oldValue);
                return;
            }

            if (axis.isLogAxis() && (val <= 0)) {
                textField.setText(oldValue);
                return;
            }
            textField.setText(Double.toString(val));
        }
    });

    textField.setOnKeyPressed(ke -> {
        if (ke.getCode().equals(KeyCode.ENTER)) {
            final double presentValue = Double.parseDouble(textField.getText());
            if (isLowerBound && !axis.isInvertedAxis()) {
                axis.setMin(presentValue);
            } else {
                axis.setMax(presentValue);
            }
            axis.setAutoRanging(false);

            if (axis instanceof AbstractAxis) {
                // ((AbstractAxis) axis).recomputeTickMarks();
                axis.setTickUnit(((AbstractAxis) axis).computePreferredTickUnit(axis.getLength()));
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("recompute axis tick unit to {}",
                            ((AbstractAxis) axis).computePreferredTickUnit(axis.getLength()));
                }
            }
        }
    });

    HBox.setHgrow(textField, Priority.ALWAYS);
    VBox.setVgrow(textField, Priority.ALWAYS);

    return textField;
}
 
源代码19 项目: DashboardFx   文件: ViewerSkin.java
@Override
void mouseReleased() {
    TextField textField = getSkinnable();
    textField.setText(textField.getText());
    textField.end();
}
 
源代码20 项目: pikatimer   文件: PikaRFIDDirectReader.java
private void setClockDialog(){
    Integer localTZ = TimeZone.getDefault().getOffset(System.currentTimeMillis())/3600000;
    Integer ultraTZ = Integer.parseInt(ultraSettings.get("23"));

    // open a dialog box 
    Dialog<Boolean> dialog = new Dialog();
    dialog.setTitle("Set Ultra Clock");
    dialog.setHeaderText("Set the clock for " + ultraIP);
    ButtonType setButtonType = new ButtonType("Set", ButtonBar.ButtonData.OK_DONE);
    dialog.getDialogPane().getButtonTypes().addAll(setButtonType, ButtonType.CANCEL);
    
    VBox clockVBox = new VBox();
    clockVBox.setStyle("-fx-font-size: 16px;");
    
    CheckBox useComputer = new CheckBox("Sync with the local computer");
    VBox manualVBox = new VBox();
    manualVBox.setSpacing(5.0);
    manualVBox.disableProperty().bind(useComputer.selectedProperty());
    
    HBox dateHBox = new HBox();
    dateHBox.setSpacing(5.0);
    Label dateLabel = new Label("Date:");
    dateLabel.setMinWidth(40);
    DatePicker ultraDate = new DatePicker();
    dateHBox.getChildren().addAll(dateLabel,ultraDate);
    
    HBox timeHBox = new HBox();
    timeHBox.setSpacing(5.0);
    Label timeLabel = new Label("Time:");
    timeLabel.setMinWidth(40);
    TextField ultraTime = new TextField();
    timeHBox.getChildren().addAll(timeLabel,ultraTime);
    
    HBox tzHBox = new HBox();
    tzHBox.setSpacing(5.0);
    Label tzLabel = new Label("TimeZone:");
    tzLabel.setMinWidth(40);
    Spinner<Integer> tzSpinner = new Spinner<>(-23, 23, localTZ);    
    tzHBox.getChildren().addAll(tzLabel,tzSpinner);

    manualVBox.getChildren().addAll(dateHBox,timeHBox,tzHBox);
    
    CheckBox autoGPS = new CheckBox("Use GPS to auto-set the clock");
    autoGPS.setSelected(true);

    
    clockVBox.getChildren().addAll(useComputer,manualVBox,autoGPS);
    dialog.getDialogPane().setContent(clockVBox);
    
    BooleanProperty timeOK = new SimpleBooleanProperty(false);

    ultraTime.textProperty().addListener((observable, oldValue, newValue) -> {
        timeOK.setValue(false);
        if (DurationParser.parsable(newValue)) timeOK.setValue(Boolean.TRUE);
        if ( newValue.isEmpty() || newValue.matches("^[0-9]*(:?([0-5]?([0-9]?(:([0-5]?([0-9]?)?)?)?)?)?)?") ){
            System.out.println("Possiblely good start Time (newValue: " + newValue + ")");
        } else {
            Platform.runLater(() -> {
                int c = ultraTime.getCaretPosition();
                if (oldValue.length() > newValue.length()) c++;
                else c--;
                ultraTime.setText(oldValue);
                ultraTime.positionCaret(c);
            });
            System.out.println("Bad clock time (newValue: " + newValue + ")");
        }
    });
    
    
    ultraDate.setValue(LocalDate.now());
    ultraTime.setText(LocalTime.ofSecondOfDay(LocalTime.now().toSecondOfDay()).toString());

    Node createButton = dialog.getDialogPane().lookupButton(setButtonType);
    createButton.disableProperty().bind(timeOK.not());
    
    dialog.setResultConverter(dialogButton -> {
        if (dialogButton == setButtonType) {
            return Boolean.TRUE;
        }
        return null;
    });

    Optional<Boolean> result = dialog.showAndWait();

    if (result.isPresent()) {
        if (useComputer.selectedProperty().get()) {
            System.out.println("Timezone check: Local :" + localTZ + " ultra: " + ultraTZ);
            if (localTZ.equals(ultraTZ)) setClock(LocalDateTime.now(),null,autoGPS.selectedProperty().get());
            else setClock(LocalDateTime.now(),localTZ,autoGPS.selectedProperty().get());
        } else {
            LocalTime time = LocalTime.MIDNIGHT.plusSeconds(DurationParser.parse(ultraTime.getText()).getSeconds());
            Integer newTZ = tzSpinner.getValue();
            if (newTZ.equals(ultraTZ)) setClock(LocalDateTime.of(ultraDate.getValue(), time),null,autoGPS.selectedProperty().get());
            else {
                setClock(LocalDateTime.of(ultraDate.getValue(), time),newTZ,autoGPS.selectedProperty().get());
            }
        }
        
    }
}