摆动javafx应用与未装饰的框架

时间:2016-01-31 19:22:13

标签: java swing javafx

我完全不明白这是不行的,如果我能得到一个,我想解决这个问题。我试图摆脱框架退出按钮,最小化和恢复等,以便我可以设置自己的,但我的程序涉及javafx并且不允许setUndecorated()方法工作。

import java.awt.Dimension;

import javax.swing.JFrame;

import javafx.application.Application;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Test extends JFrame {

    private final int WIDTH = 600;
    private final int HEIGHT = 300;

    public Test() {
        JFXPanel fxpanel = new JFXPanel();
        fxpanel.setScene(createScene(this));
        add(fxpanel);
        setTitle("Frame");
        setSize(new Dimension(WIDTH, HEIGHT));
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
        setResizable(false);
        setLocationRelativeTo(null);
        // setUndecorated(true); would go here.. but it doesn't work.


    }

    private Scene createScene(JFrame frame) {
        StackPane root = new StackPane();
        Scene scene = new Scene(root, Color.ALICEBLUE);
        Text text = new Text();

        text.setX(150);
        text.setY(100);
        text.setFont(new Font(25));
        text.setText("Welcome JavaFX!");

        root.getChildren().add(text);

        return (scene);
    }

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

1 个答案:

答案 0 :(得分:0)

你必须在setVisible

之前调用setUndecorated