0
public void frame(Rectangle rechteck) {
rechteck.setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
rechteck.setStroke(Color.DARKGREY);
}
});
rechteck.setOnMouseExited((MouseEvent e) -> {
rechteck.setStroke(Color.BLUE);
});
}
我试图让'悬停'效果。我有不同的矩形,当我进入矩形时,它会得到一个灰色的笔画。当光标离开矩形时,笔画应该再次消失。setOnMouseExited不适用于笔划?
为什么我的笔画总是灰色,并且在我离开矩形时不会改变。
如何禁用笔划?如果我退出矩形,我实际上不想将颜色更改为蓝色,但我希望它不再存在。
编辑:休息
@Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
// Die Linie in der Mitte.
Rectangle line = new Rectangle(0, 0, 450, 1);
root.getChildren().add(line);
// Das abgerundete Rechteck.
Rectangle roundedRect = new Rectangle(0, 0, 300, 80);
roundedRect.setStroke(Color.BLACK);
roundedRect.setArcWidth(40);
roundedRect.setArcHeight(40);
roundedRect.setFill(Color.BISQUE);
root.getChildren().add(roundedRect);
// Die Farblinien.
Rectangle firstLine = new Rectangle(100, 0, 25, 80);
firstLine.setFill(Color.BROWN);
frame(firstLine);
Rectangle secondLine = new Rectangle(0, 0, 25, 80);
secondLine.setFill(Color.BLACK);
frame(secondLine);
Rectangle thirdLine = new Rectangle(0, 0, 25, 80);
thirdLine.setFill(Color.RED);
frame(thirdLine);
Rectangle fourthLine = new Rectangle(0, 0, 25, 80);
fourthLine.setFill(Color.GOLD);
frame(fourthLine);
HBox lines = new HBox();
lines.setAlignment(Pos.CENTER);
lines.setPadding(new Insets(30));
HBox.setMargin(firstLine, new Insets(0, 30, 0, 0));
HBox.setMargin(secondLine, new Insets(0, 30, 0, 0));
HBox.setMargin(thirdLine, new Insets(0, 30, 0, 0));
HBox.setMargin(fourthLine, new Insets(0, 0, 0, 50));
lines.getChildren().addAll(firstLine, secondLine, thirdLine, fourthLine);
double widerstand = (ERSTERRING + ZWEITERRING) * DRITTERRING;
char groesse = ' ';
if (widerstand >= 1000 && widerstand < 10000) {
widerstand = widerstand/1000;
groesse = 'k';
} else if (widerstand >= 1000000) {
widerstand = widerstand/1000000;
groesse = 'M';
}
VBox vbox = new VBox();
Text werte = new Text(90, 210, "R = " + widerstand + groesse + "Ω mit " + VIERTERRING + " % Toleranz");
VBox.setMargin(werte, new Insets(200, 0, 0, 70));
vbox.getChildren().add(werte);
root.getChildren().add(vbox);
root.getChildren().add(lines);
Scene scene = new Scene(root, 450, 300);
primaryStage.setTitle("Widerstandsrechner");
primaryStage.setScene(scene);
primaryStage.show();
}