[英]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.
我试图摆脱帧退出按钮,最小化和还原等,以便可以设置自己的按钮,但是我的程序涉及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();
}
}
您必须在setVisible之前调用setUndecorated
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.