我需要将绘制的矩形鼠标透明,以便查看桌面.
以下代码绘制了我的矩形.我应该添加什么来获得它?
感谢帮助
public void start(Stage primaryStage) {
Group group = new Group();
Rectangle rect = new Rectangle(20,20,200,200);
rect.setArcHeight(15);
rect.setArcWidth(15);
rect.setStroke(Color.BLACK);
group.getChildren().add(rect);
Scene scene = new Scene(group, 300, 200);
primaryStage.setScene(scene);
primaryStage.show();
}
解决方法:
由于JavaFX中的屏幕图形是分层结构,要显示桌面,您还需要使舞台和场景透明,并使用形状“算术”:
@Override
public void start(Stage stage) {
Group group = new Group();
Rectangle rect = new Rectangle(0, 0, 350, 300);
Rectangle clip = new Rectangle(20, 20, 200, 200);
clip.setArcHeight(15);
clip.setArcWidth(15);
Shape shape = Shape.subtract(rect, clip);
shape.setFill(Color.GRAY);
group.getChildren().add(shape);
Scene scene = new Scene(group);
scene.setFill(Color.TRANSPARENT);
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
stage.show();
}
稍后您可以向窗格/组添加可拖动功能.