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

时间:2021-08-15 17:02:57

I am trying to create a custom stage in javafx 2.0. I want that my stage drops shadow on the screen as dropped by other windows... I tried with following code :

我想在javafx 2.0中创建一个自定义阶段。我希望我的舞台在屏幕上投下阴影,因为其他窗口掉落了......我尝试使用以下代码:

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 : 在javafx 2.0中创建未修饰的阶段

这是在白色屏幕上拍摄的屏幕:

And this on colored screen: 在javafx 2.0中创建未修饰的阶段

这在彩色屏幕上:

HOw to resolve this issue?? Please help.

请问解决这个问题?请帮忙。

1 个解决方案

#1


10  

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();
    }
}

#1


10  

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();
    }
}