我的问题是当我从Windows任务栏恢复最小化的javafx应用程序时,WebView被禁用。
调整大小后,它会启用。
主要java代码:
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
AnchorPane root = new AnchorPane();
FXMLLoader loader = new FXMLLoader(getClass().getResource("Browser.fxml"));
root = loader.load();
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("Shivam Jewels ERP");
primaryStage.setMaximized(true);
primaryStage.show();
primaryStage.iconifiedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
if (t1) {
System.out.println("minimized:");
}
}
});
primaryStage.maximizedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if (newValue) {
System.out.println("maximized:");
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
我的JavaFX代码是:
public class BrowserController implements Initializable {
@FXML
private WebView browser;
@FXML
private GridPane grdPn;
@Override
public void initialize(URL location, ResourceBundle resources) {
final WebEngine webEngine = browser.getEngine();
browser.getEngine().setUserStyleSheetLocation(getClass().getResource("application.css").toExternalForm());
browser.setContextMenuEnabled(false);
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
webEngine.load("http://192.168.2.6:4200");
}
}
这是我的CSS代码:
::-webkit-scrollbar {
width: 6px;
}
::-webkit-scrollbar-track {
-webkit-border-radius: 10px;
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
-webkit-border-radius: 10px;
border-radius: 10px;
background: rgba(0,0,0,0.5);
}
::-webkit-scrollbar-thumb:window-inactive {
background: rgba(0,0,0,0.1);
}
这是我的FXML代码:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.web.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="382.0" prefWidth="353.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.BrowserController">
<children>
<GridPane fx:id="grdPn" layoutX="57.0" layoutY="135.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" />
</columnConstraints>
<rowConstraints>
<RowConstraints fillHeight="false" valignment="CENTER" vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
</rowConstraints>
<children>
<WebView fx:id="browser" minHeight="-1.0" minWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" GridPane.valignment="CENTER" GridPane.vgrow="ALWAYS" />
</children>
</GridPane>
</children>`enter code here`
</AnchorPane>
答案 0 :(得分:3)
这实际上是多次报告here,here和here的JDK错误。您描述的行为会在List<String> arrobj= new ArrayList<String>();
arrobj.add("food");
arrobj.add("drinks");
arrobj.add("snack");
for (String value : arrobj) {
if (value.equals("snack")) {
System.out.println("Here is the snack");
}
}
最大化时发生。
此错误计划在JDK9中修复,但根据this也将在JDK8u122中修复:
批准向8u-dev追回8u122。
JDK 8u122 is planned将于2017年1月发布,因此我们可以使用它不久,但现在您可以从JDK 8u122 early access page下载并使用早期访问版本。
我自己下载并测试了代码,幸运的是问题不再存在。