在以下简化的JavaFx程序中,它一直说应用程序不响应。当我注释掉Platform.runLater(新的Runnable(){...}它不会崩溃。任何想法是错误的,我怎么能解决这个问题?JavaFx Platform.runLater应用程序未响应
package apptest;
import java.awt.BorderLayout;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class apptest {
public static JFXPanel jfxPanel = new JFXPanel();
public static void main(String[] args){
final JFrame frame = new JFrame();
Platform.runLater(new Runnable() {
@Override
public void run() {
JPanel login = new JPanel();
login.setLayout(new BorderLayout());
login.setBounds(0, 0, 415, 180);
WebView webView = new WebView();
WebEngine engine = webView.getEngine();
engine.load("http://www.google.com");
VBox root = new VBox(webView);
root.setStyle("-fx-focus-color: transparent;");
Scene scene = new Scene(root,414,179);
ScrollPane scrollPane = new ScrollPane();
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setContent(webView);
root.getChildren().addAll(scrollPane);
jfxPanel.setScene(scene);
frame.add(login, BorderLayout.NORTH);
login.add(jfxPanel, BorderLayout.NORTH);
}
});
frame.setLayout(null);
frame.setSize(415,180);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setAlwaysOnTop(true);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds();
int x = 10;
int y = (int) rect.getMaxY() - (frame.getHeight() + 50);
frame.setLocation(x, y);
frame.setVisible(true);
}
}