本文介绍了JavaFX 对背景的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 ,而不是aero.
这可能很重要:我使用的是 Undecorator 的修改版本.>
解决方案
import javafx.animation.*;导入 javafx.application.*;导入 javafx.beans.property.*;导入 javafx.embed.swing.SwingFXUtils;导入 javafx.geometry.Insets;导入 javafx.scene.*;导入 javafx.scene.control.Label;导入 javafx.scene.effect.*;导入 javafx.scene.Cursor;导入 javafx.scene.Node;导入 javafx.scene.image.*;导入 javafx.scene.layout.StackPane;导入 javafx.scene.paint.Color;导入 javafx.stage.Stage;导入 javafx.stage.StageStyle;导入 javafx.util.Duration;公共类 FrostyTech 扩展应用程序 {私人静态最终双 BLUR_AMOUNT = 10;私有静态最终效果frostEffect =新 BoxBlur(BLUR_AMOUNT, BLUR_AMOUNT, 3);private static final ImageView background = new ImageView();private static final StackPane layout = new StackPane();@Override public void start(Stage stage) {layout.getChildren().setAll(background, createContent());layout.setStyle("-fx-background-color: null");场景场景 = 新场景(布局,200, 300,颜色.透明);Platform.setImplicitExit(false);scene.setOnMouseClicked(事件 -> {if (event.getClickCount() == 2) Platform.exit();});makeSmoke(舞台);stage.initStyle(StageStyle.TRANSPARENT);stage.setScene(场景);舞台表演();background.setImage(copyBackground(stage));background.setEffect(frostEffect);makeDraggable(舞台,布局);}//复制一个要冻结的背景节点.私人图像复制背景(舞台舞台){final int X = (int) stage.getX();final int Y = (int) stage.getY();final int W = (int) stage.getWidth();final int H = (int) stage.getHeight();尝试 {java.awt.Robot 机器人 = 新的 java.awt.Robot();java.awt.image.BufferedImage image = robots.createScreenCapture(new java.awt.Rectangle(X, Y, W, H));返回 SwingFXUtils.toFXImage(image, null);} catch (java.awt.AWTException e) {System.out.println("末日机器人来袭!");e.printStackTrace();返回空;}}//创建一些要显示在冻结玻璃面板顶部的内容.私有标签 createContent() {Label label = new Label("为阴影效果创建一个新问题.
拖动移动
双击关闭");label.setPadding(new Insets(10));label.setStyle("-fx-font-size: 15px; -fx-text-fill: green;");label.setMaxWidth(250);label.setWrapText(true);退货标签;}//使用给定节点使舞台可拖动.public void makeDraggable(final Stage stage, final Node byNode) {最终 Delta dragDelta = new Delta();byNode.setOnMousePressed(mouseEvent -> {//记录拖放操作的增量距离.dragDelta.x = stage.getX() - mouseEvent.getScreenX();dragDelta.y = stage.getY() - mouseEvent.getScreenY();byNode.setCursor(Cursor.MOVE);});final BooleanProperty inDrag = new SimpleBooleanProperty(false);byNode.setOnMouseReleased(mouseEvent -> {byNode.setCursor(Cursor.HAND);如果(inDrag.get()){隐藏();时间线暂停 = 新时间线(新关键帧(Duration.millis(50),事件 -> {background.setImage(copyBackground(stage));布局.getChildren().set(0,背景);舞台表演();}));暂停播放();}inDrag.set(false);});byNode.setOnMouseDragged(mouseEvent -> {stage.setX(mouseEvent.getScreenX() + dragDelta.x);stage.setY(mouseEvent.getScreenY() + dragDelta.y);布局.getChildren().set(0,makeSmoke(舞台));inDrag.set(true);});byNode.setOnMouseEntered(mouseEvent -> {if (!mouseEvent.isPrimaryButtonDown()) {byNode.setCursor(Cursor.HAND);}});byNode.setOnMouseExited(mouseEvent -> {if (!mouseEvent.isPrimaryButtonDown()) {byNode.setCursor(Cursor.DEFAULT);}});}私人 javafx.scene.shape.Rectangle makeSmoke(Stage stage) {返回新的 javafx.scene.shape.Rectangle(stage.getWidth(),stage.getHeight(),Color.WHITESMOKE.deriveColor(0, 1, 1, 0.08));}/** 记录相对的 x 和 y 坐标.*/私有静态类 Delta {双 x, y;}公共静态无效主(字符串 [] args){发射(参数);}}
相关问题
I'm using this to make a iOS-themed JavaFX2 (Java7) application with a frosted glass effect. The problem is that this code uses its effect on an ImageView. I'd like it to use its effect on whatever's behind the window, like this:
Is there anyway to do that? I'd also like that small drop-shadow effect you see around the above image.
To be clear, I don't want that slider or anything, just the effect of being able to see through the window and having that slight shadow around the edges. I want to use this iOS7-ish effect instead of aero, though.
This might be important: I'm using a modified version of Undecorator.
解决方案
import javafx.animation.*;
import javafx.application.*;
import javafx.beans.property.*;
import javafx.embed.swing.SwingFXUtils;
import javafx.geometry.Insets;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.effect.*;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.image.*;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;
public class FrostyTech extends Application {
private static final double BLUR_AMOUNT = 10;
private static final Effect frostEffect =
new BoxBlur(BLUR_AMOUNT, BLUR_AMOUNT, 3);
private static final ImageView background = new ImageView();
private static final StackPane layout = new StackPane();
@Override public void start(Stage stage) {
layout.getChildren().setAll(background, createContent());
layout.setStyle("-fx-background-color: null");
Scene scene = new Scene(
layout,
200, 300,
Color.TRANSPARENT
);
Platform.setImplicitExit(false);
scene.setOnMouseClicked(event -> {
if (event.getClickCount() == 2) Platform.exit();
});
makeSmoke(stage);
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
stage.show();
background.setImage(copyBackground(stage));
background.setEffect(frostEffect);
makeDraggable(stage, layout);
}
// copy a background node to be frozen over.
private Image copyBackground(Stage stage) {
final int X = (int) stage.getX();
final int Y = (int) stage.getY();
final int W = (int) stage.getWidth();
final int H = (int) stage.getHeight();
try {
java.awt.Robot robot = new java.awt.Robot();
java.awt.image.BufferedImage image = robot.createScreenCapture(new java.awt.Rectangle(X, Y, W, H));
return SwingFXUtils.toFXImage(image, null);
} catch (java.awt.AWTException e) {
System.out.println("The robot of doom strikes!");
e.printStackTrace();
return null;
}
}
// create some content to be displayed on top of the frozen glass panel.
private Label createContent() {
Label label = new Label("Create a new question for drop shadow effects.
Drag to move
Double click to close");
label.setPadding(new Insets(10));
label.setStyle("-fx-font-size: 15px; -fx-text-fill: green;");
label.setMaxWidth(250);
label.setWrapText(true);
return label;
}
// makes a stage draggable using a given node.
public void makeDraggable(final Stage stage, final Node byNode) {
final Delta dragDelta = new Delta();
byNode.setOnMousePressed(mouseEvent -> {
// record a delta distance for the drag and drop operation.
dragDelta.x = stage.getX() - mouseEvent.getScreenX();
dragDelta.y = stage.getY() - mouseEvent.getScreenY();
byNode.setCursor(Cursor.MOVE);
});
final BooleanProperty inDrag = new SimpleBooleanProperty(false);
byNode.setOnMouseReleased(mouseEvent -> {
byNode.setCursor(Cursor.HAND);
if (inDrag.get()) {
stage.hide();
Timeline pause = new Timeline(new KeyFrame(Duration.millis(50), event -> {
background.setImage(copyBackground(stage));
layout.getChildren().set(
0,
background
);
stage.show();
}));
pause.play();
}
inDrag.set(false);
});
byNode.setOnMouseDragged(mouseEvent -> {
stage.setX(mouseEvent.getScreenX() + dragDelta.x);
stage.setY(mouseEvent.getScreenY() + dragDelta.y);
layout.getChildren().set(
0,
makeSmoke(stage)
);
inDrag.set(true);
});
byNode.setOnMouseEntered(mouseEvent -> {
if (!mouseEvent.isPrimaryButtonDown()) {
byNode.setCursor(Cursor.HAND);
}
});
byNode.setOnMouseExited(mouseEvent -> {
if (!mouseEvent.isPrimaryButtonDown()) {
byNode.setCursor(Cursor.DEFAULT);
}
});
}
private javafx.scene.shape.Rectangle makeSmoke(Stage stage) {
return new javafx.scene.shape.Rectangle(
stage.getWidth(),
stage.getHeight(),
Color.WHITESMOKE.deriveColor(
0, 1, 1, 0.08
)
);
}
/** records relative x and y co-ordinates. */
private static class Delta {
double x, y;
}
public static void main(String[] args) {
launch(args);
}
}
Related Questions
- Frosted Glass Effect in JavaFX?
- How do I create a JavaFX transparent stage with shadows on only the border?
这篇关于JavaFX 对背景的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!