在以下簡化的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);
}
}