【发布时间】:2016-04-21 10:14:51
【问题描述】:
在以下简化的 JavaFx 程序中,它一直说 Application Not Responsive。当我注释掉 Platform.runLater(new Runnable() {...} 时,它不会崩溃。任何想法有什么问题以及如何解决它?
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);
}
}
【问题讨论】: