简体   繁体   English

在javafx 2.0中创建未修饰的阶段

[英]creating undecorated stage in javafx 2.0

I am trying to create a custom stage in javafx 2.0. 我想在javafx 2.0中创建一个自定义阶段。 I want that my stage drops shadow on the screen as dropped by other windows... I tried with following code : 我希望我的舞台在屏幕上投下阴影,因为其他窗口掉落了......我尝试使用以下代码:

public class ChatWindow {
final private Stage stage = new Stage(StageStyle.UNDECORATED);
private Scene scene;
private Group rg;
private Text t = new Text();
private double initx = 0, inity = 0;

public ChatWindow() {

    rg = new Group();
    scene = new Scene(rg, 320, 240);
    //scene.setFill(null);
    scene.setFill(new Color(0, 0, 0, 0));
    stage.setScene(scene);
    stage.show();
    setupStage();
}

private void setupStage() {
    Rectangle r = new Rectangle(5, 5, stage.getWidth() - 10, stage.getHeight() - 10);
    r.setFill(Color.STEELBLUE);
    r.setEffect(new DropShadow());
    rg.setOnMousePressed(new EventHandler<MouseEvent>() {
        public void handle(MouseEvent me) {
            initx = me.getScreenX() - stage.getX();// - me.getSceneX(); 
            inity = me.getScreenY() - stage.getY();
        }
    });
    rg.setOnMouseDragged(new EventHandler<MouseEvent>() {

        public void handle(MouseEvent me) {
            stage.setX(me.getScreenX() - initx);
            stage.setY(me.getScreenY() - inity);
        }
    });
    rg.getChildren().add(r);
    rg.getChildren().add(t);
}

public void setVisible() {
    stage.show();
}
}

I can see the shadow fall, but actually their is a white background on which its falling. 我可以看到阴影落下,但实际上它们是一个白色的背景,它的下降。 So, its useless, as on colored screen the defect will be visible, will make it look ugly.. 所以,它的无用,就像在彩色屏幕上看到的缺陷一样,会让它看起来很难看。

This is the screen shot on white screen : 这是在白色屏幕上拍摄的屏幕: 在此输入图像描述

And this on colored screen: 这在彩色屏幕上: 在此输入图像描述

HOw to resolve this issue?? 请问解决这个问题? Please help. 请帮忙。

You should set style StageStyle.TRANSPARENT , see next code: 您应该设置样式StageStyle.TRANSPARENT ,请参阅下一个代码:

public class ChatWindow extends Application {

    @Override
    public void start(final Stage stage) throws Exception {
        stage.initStyle(StageStyle.TRANSPARENT); // here it is

        Group rg = new Group();
        Scene scene = new Scene(rg, 320, 240, Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();

        Rectangle r = new Rectangle(5, 5, stage.getWidth() - 10, stage.getHeight() - 10);
        r.setFill(Color.STEELBLUE);
        r.setEffect(new DropShadow());
        rg.getChildren().add(r);
    }

    public static void main(String[] args) {
        launch();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM