Java Code Examples for javafx.scene.control.TextField#setStyle()

The following examples show how to use javafx.scene.control.TextField#setStyle() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private void checkMatrix() {
    if (isSettingValues) {
        return;
    }
    if (matrixInputs == null || matrixValues == null) {
        matrixValid = false;
        return;
    }
    matrixValid = true;
    for (int j = 0; j < height; ++j) {
        for (int i = 0; i < width; ++i) {
            TextField valueInput = matrixInputs[j][i];
            try {
                matrixValues[j][i] = Float.valueOf(valueInput.getText());
                valueInput.setStyle(null);
            } catch (Exception e) {
                matrixValid = false;
                valueInput.setStyle(badStyle);
            }
        }
    }
    checkKernel();
}
 
Example 2
Source Project: MyBox   File: FxmlControl.java    License: Apache License 2.0 6 votes vote down vote up
public static void setFileValidation(final TextField input, String key) {
    if (input == null) {
        return;
    }
    input.setStyle(badStyle);
    input.textProperty().addListener(
            (ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
                String v = input.getText();
                if (v == null || v.isEmpty()) {
                    input.setStyle(badStyle);
                    return;
                }
                final File file = new File(newValue);
                if (!file.exists() || !file.isFile()) {
                    input.setStyle(badStyle);
                    return;
                }
                input.setStyle(null);
                AppVariables.setUserConfigValue(key, file.getParent());
            });
}
 
Example 3
public NeutralMassComponent() {

    add(new Label("m/z:"), 0, 0);

    ionMassField = new TextField();
    ionMassField.textProperty().addListener((observable, oldValue, newValue) -> {
      updateNeutralMass();
    });
    ionMassField.setPrefColumnCount(8);
    add(ionMassField, 1, 0);

    add(new Label("Charge:"), 2, 0);

    chargeField = new TextField();
    chargeField.textProperty().addListener((observable, oldValue, newValue) -> {
      updateNeutralMass();
    });
    chargeField.setPrefColumnCount(2);
    add(chargeField, 3, 0);

    add(new Label("Ionization type:"), 0, 1, 2, 1);
    ionTypeCombo =
        new ComboBox<IonizationType>(FXCollections.observableArrayList(IonizationType.values()));
    ionTypeCombo.setOnAction(e -> {
      updateNeutralMass();
    });
    add(ionTypeCombo, 2, 1, 2, 1);

    add(new Label("Calculated mass:"), 0, 2, 2, 1);

    neutralMassField = new TextField();
    neutralMassField.setPrefColumnCount(8);
    neutralMassField.setStyle("-fx-background-color: rgb(192, 224, 240);");
    neutralMassField.setEditable(false);
    add(neutralMassField, 2, 2, 2, 1);

  }
 
Example 4
Source Project: MyBox   File: FxmlControl.java    License: Apache License 2.0 5 votes vote down vote up
public static int positiveValue(final TextField input, final int max) {
    try {
        int v = Integer.parseInt(input.getText());
        if (v > 0 && v <= max) {
            input.setStyle(null);
            return v;
        } else {
            input.setStyle(badStyle);
            return -1;
        }
    } catch (Exception e) {
        input.setStyle(badStyle);
        return -1;
    }
}
 
Example 5
private boolean validateDistanceField(TextField field) {
	boolean isValid = true;

	if (field.getText().isEmpty()) {
		isValid = false;
		field.setStyle("-fx-text-box-border: red; -fx-focus-color: red;");
	} else {
		field.setStyle("");
	}

	return isValid;
}
 
Example 6
Source Project: oim-fx   File: MainFlatTest.java    License: MIT License 4 votes vote down vote up
/**
 * 测试数据
 */
private void initTest() {
	// stage.setBackgroundColor(Color.rgb(245,245,245,1));

	userFindPane.setStyle("-fx-background-color:rgba(255, 255, 255, 1)");

	userListPane.getBorderPane().setStyle("-fx-background-color:rgba(246, 246, 246, 1)");

	lastMainPane.setStyle("-fx-background-color:rgba(240, 243, 246, 1)");

	lastRoot.setStyle("-fx-background-color:rgba(246, 246, 246, 1)");
	userRoot.setStyle("-fx-background-color:rgba(246, 246, 246, 1)");

	userMainPane.setLeftWidth(230);
	lastMainPane.setLeftWidth(230);

	userMainPane.setLeftCenter(userListPane);
	lastMainPane.setLeftCenter(lastRoot);

	Image normalImage = ImageBox.getImageClassPath("/flat/images/main/tab/message_normal.png");
	Image hoverImage = ImageBox.getImageClassPath("/flat/images/main/tab/message_hover.png");
	Image selectedImage = ImageBox.getImageClassPath("/flat/images/main/tab/message_selected.png");

	mainFlatPane.addTab(normalImage, hoverImage, selectedImage, lastMainPane);

	normalImage = ImageBox.getImageClassPath("/flat/images/main/tab/user_normal.png");
	hoverImage = ImageBox.getImageClassPath("/flat/images/main/tab/user_hover.png");
	selectedImage = ImageBox.getImageClassPath("/flat/images/main/tab/user_selected.png");

	mainFlatPane.addTab(normalImage, hoverImage, selectedImage, userMainPane);

	normalImage = ImageBox.getImageClassPath("/bine/main/images/tab/group_normal.png");
	hoverImage = ImageBox.getImageClassPath("/bine/main/images/tab/group_hover.png");
	selectedImage = ImageBox.getImageClassPath("/bine/main/images/tab/group_selected.png");

	// lastRoot = new ListRootPanel();
	// lastRoot.setStyle("-fx-background-color:rgba(144, 50, 59, 0.8)");
	// mainFlatPane.addTab(normalImage, hoverImage, selectedImage,
	// lastRoot);
	TextField textField = userListPane.getTextField();
	textField.textProperty().addListener(new ChangeListener<String>() {

		@Override
		public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
			//String text = textField.getText();
		}
	});
	textField.setStyle("-fx-border-color: #666666;\r\n" +
			"    -fx-border-width: 1px;\r\n" +
			"    -fx-border-style: solid;");
}
 
Example 7
Source Project: Quelea   File: WebPanel.java    License: GNU General Public License v3.0 4 votes vote down vote up
private void setupNavigationBarContent() {
    back = new Button("", getButtonImageView("file:icons/arrow-back.png"));
    back.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.back();
        }
    });
    forward = new Button("", getButtonImageView("file:icons/arrow-forward.png"));
    forward.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.forward();
        }
    });
    reload = new Button("", getButtonImageView("file:icons/reload.png"));
    reload.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.reload();
        }
    });
    url = new TextField();
    url.setPrefHeight(32);
    url.setMaxHeight(32);
    url.setStyle(""
            + "-fx-font-size: 14px;"
            + "-fx-font-weight: bold;"
            + "-fx-font-family: fantasy;");
    url.setTooltip(new Tooltip("Change URL"));
    url.setOnKeyReleased(e -> {
        if (e.getCode().equals(KeyCode.ENTER)) {
            if (wd != null) {
                wd.setUrl(url.getText());
            }
        }
    });
    go = new Button("", getButtonImageView("file:icons/send.png"));
    go.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.setUrl(url.getText());
        }
    });
    plus = new Button("", getButtonImageView("file:icons/zoom-in.png"));
    plus.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.zoom(true);
        }
    });
    minus = new Button("", getButtonImageView("file:icons/zoom-out.png"));
    minus.setOnMouseClicked(e -> {
        if (wd != null) {
            wd.zoom(false);
        }
    });
}
 
Example 8
Source Project: arma-dialog-creator   File: SearchTextField.java    License: MIT License 4 votes vote down vote up
/**
 Create a search text field with a provided {@link #textProperty()} change listener

 @param textPropertyListener change listener
 */
public SearchTextField(@Nullable ChangeListener<String> textPropertyListener) {
	setAlignment(Pos.CENTER_LEFT);

	tf = new TextField();
	tf.setStyle("-fx-background-color:transparent;-fx-background-radius: 0;");
	tf.setPadding(new Insets(5));

	tf.setPromptText(Lang.FxControlBundle().getString("SearchTextField.search"));
	ImageView imageView = new ImageView(SEARCH_ICON);
	StackPane stackPane = new StackPane(imageView);
	stackPane.setPadding(new Insets(5, 0, 5, 5));
	HBox hBox = new HBox(0, stackPane, tf);
	HBox.setHgrow(tf, Priority.ALWAYS);
	hBox.setCursor(Cursor.TEXT);
	hBox.setOnMouseClicked(new EventHandler<MouseEvent>() {
		@Override
		public void handle(MouseEvent event) {
			tf.requestFocus();
			tf.selectEnd();
			tf.deselect();
		}
	});
	getStyleClass().add(STYLE_CLASS);
	tf.focusedProperty().addListener(new ChangeListener<Boolean>() {
		@Override
		public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean focused) {
			if (focused) {
				if (!getStyleClass().contains(STYLE_CLASS_FOCUSED)) {
					getStyleClass().add(STYLE_CLASS_FOCUSED);
				}
			} else {
				getStyleClass().remove(STYLE_CLASS_FOCUSED);
			}
		}
	});
	getChildren().add(hBox);

	if (textPropertyListener != null) {
		textProperty().addListener(textPropertyListener);
	}
}