我在java中创建了一个小脚本,应该打开一个加载特定.html文件的全屏webview,该程序应该在linux上工作,但似乎并非如此。 这里是我用来打开网页视图的代码:
public class MainBrowser extends Application {
private Scene scene;
@Override
public void start(Stage stage) {
// create the scene
stage.setTitle("Web View");
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double width = screenSize.getWidth();
double height = screenSize.getHeight();
scene = new Scene(new Browser(),width,height, Color.web("#666970"));
stage.setScene(scene);
//scene.getStylesheets().add("webviewsample/BrowserToolbar.css");
stage.setFullScreen(true);
stage.show();
}
public static void main(){
launch();
}
}
package monitor;
import java.io.File;
import java.net.URL;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
class Browser extends Region {
final WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
public Browser() {
//apply the styles
getStyleClass().add("browser");
// load the web page
File openpage = new File(Config.PAGE_LOCAL_URL);
webEngine.load(openpage.toURI().toString());
//add the web view to the scene
getChildren().add(browser);
}
private Node createSpacer() {
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
return spacer;
}
@Override protected void layoutChildren() {
double w = getWidth();
double h = getHeight();
layoutInArea(browser,0,0,w,h,0, HPos.CENTER, VPos.CENTER);
}
@Override protected double computePrefWidth(double height) {
return 750;
}
@Override protected double computePrefHeight(double width) {
return 500;
}
}
它似乎在Windows上运行得很好,但是当我在linux上运行程序它冻结时,我甚至没有得到异常,它只是冻结了。
这是我第一次处理linux,我希望比我更专业的人可以帮助我理解问题所在。