Hi,
Du kannst das erreichen, indem du z.B. dem anchorPane einen envent-handler für MouseEnter und MouseExit erstellst.
Hier mal ein Bespiel:
[code=Java]import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
AnchorPane anchorPane = new AnchorPane();
TextArea textArea = new TextArea();
textArea.setPrefWidth(200);
textArea.setPrefHeight(50);
textArea.setLayoutX(10);
textArea.setLayoutY(10);
HBox hBox = new HBox();
hBox.setLayoutX(10);
hBox.setLayoutY(120);
Label label = new Label("Ich bin ein label");
hBox.getChildren().add(label);
anchorPane.getChildren().add(textArea);
anchorPane.getChildren().add(hBox);
textArea.setOnMouseEntered((event) -> {
anchorPane.setStyle("-fx-background: #FFFFFF;");
textArea.requestFocus(); // damit ein Text eingegeben werden kann
});
textArea.setOnMouseExited((event) -> {
anchorPane.setStyle("-fx-background: #FFFF00;");
anchorPane.requestFocus(); // damit eine Texteingabe nicht in der TextArea gemacht wird.
});
label.setOnMouseEntered((event) -> {
anchorPane.setStyle("-fx-background: #FFFFFF;");
});
label.setOnMouseExited((event) -> {
anchorPane.setStyle("-fx-background: #FFFF00;");
});
anchorPane.setOnMouseEntered((event) -> {
anchorPane.setStyle("-fx-background: #FFFF00;");
});
anchorPane.setOnMouseExited((event) -> {
anchorPane.setStyle("-fx-background: #FFFFFF;");
});
anchorPane.setOnMousePressed((event) -> {
anchorPane.setStyle("-fx-background: #00FFFF;");
});
Scene scene = new Scene(anchorPane,400,400);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}[/code]