简体   繁体   中英

swing javafx application with undecorated frame

I don't understand completely how this doesn't work and I would like a fix to the problem if I could get one. I'm trying to get rid of the frame exit button, minimize, and restore, etc. so that I can set my own, but my program involves javafx and doesnt allow the setUndecorated() method to work.

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

您必须在setVisible之前调用setUndecorated

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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