Hallo nochmal,
ich probiere bei kleinen Code aus damit ich in meinem größeren code ausnützen kann. Normalerweise wird actiontarget zu grid hinzugefügt und funktioniert mit css auch. hier geht es mir nur um actiontarget Farbe damit ich in spätere code ausnutzen kann.
Ich habe halt gefunden wie man in FXML CSS einbinden kann ```
```aber anscheinend muss actiontarget einen bestimmten Platz auf Container haben damit css Werte darauf übergeben wird (z.B actiontarget Farbe rot übergeben wird ). Wie gesagt ich brauche textfarbe damit ich in Formular TextField übergeben kann, wenn z.b Passworte nicht übereinstimmen und birthday enthält nicht nur Ziffern u.s.w
@Override
public void start(Stage stage) {
stage.setTitle("JavaFX Welcome");
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Text scenetitle = new Text("Welcome");
scenetitle.setId("welcome-text");
grid.add(scenetitle, 0, 0, 2, 1);
Label userName = new Label("User Name:");
grid.add(userName, 0, 1);
TextField userTextField = new TextField();
grid.add(userTextField, 1, 1);
Label pw = new Label("Password:");
grid.add(pw, 0, 2);
PasswordField pwBox = new PasswordField();
grid.add(pwBox, 1, 2);
Button btn = new Button("Sign in");
HBox hbBtn = new HBox(10);
hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
hbBtn.getChildren().add(btn);
grid.add(hbBtn, 1, 4);
final Text actiontarget = new Text();
actiontarget.setId("actiontarget");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
actiontarget.setFill(Color.RED);
actiontarget.setText("Inkorrect");
actiontarget.setFill(Color.RED);
userTextField.setText(actiontarget.getText());
actiontarget.setFill(Color.RED);
actiontarget.setId("actiontarget");
}
});
Scene scene = new Scene(grid, 300, 275);
stage.setScene(scene);
scene.getStylesheets().add(Login.class.getResource("Login.css").toExternalForm());
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}```
[XML]/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */.root {
-fx-background-color: white;
}
.label {
-fx-font-size: 12px;
-fx-font-weight: bold;
-fx-text-fill: #333333;
-fx-effect: dropshadow( gaussian , rgba(255,255,255,0.5) , 0,0,0,1 );
}
#welcome-text {
-fx-font-size: 32px;
-fx-font-family: "Arial Black";
-fx-fill: #818181;
-fx-effect: innershadow( three-pass-box , rgba(0,0,0,0.7) , 6, 0.0 , 0 , 2 );
}
#actiontarget {
-fx-fill: FIREBRICK;
-fx-font-weight: bold;
-fx-effect: dropshadow( gaussian , rgba(255,255,255,0.5) , 0,0,0,1 );
}
.button {
-fx-text-fill: white;
-fx-font-family: "Arial Narrow";
-fx-font-weight: bold;
-fx-background-color: linear-gradient(#61a2b1, #2A5058);
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 );
}
[/XML]