我想知道是否可以在 javafx 中使用媒体查询。我有一个按钮,它是网格 Pane 中的图像,当我为我的应用程序使用另一个分辨率时,网格 Pane 会适应新的分辨率,但按钮(图像)不会适应。
代码:
//gridpane
GridPane gridPaneStart = new GridPane();
gridPaneStart.setHgap(2);
gridPaneStart.setVgap(2);
gridPaneStart.prefWidthProperty().bind(window.widthProperty());
gridPaneStart.prefHeightProperty().bind(window.heightProperty());
gridPaneStart.setGridLinesVisible(true);
ColumnConstraints column1 = new ColumnConstraints();
column1.setPercentWidth(70);
ColumnConstraints column2 = new ColumnConstraints();
column2.setPercentWidth(50);
ColumnConstraints column3 = new ColumnConstraints();
column3.setPercentWidth(50);
gridPaneStart.getColumnConstraints().addAll(column1, column2, column3);
RowConstraints row1 = new RowConstraints();
row1.setPercentHeight(60);
RowConstraints row2 = new RowConstraints();
row2.setPercentHeight(20);
RowConstraints row3 = new RowConstraints();
row3.setPercentHeight(20);
gridPaneStart.getRowConstraints().addAll(row1, row2, row3);
//background
ImageView background = new ImageView("/images/start_background.png");
background.fitWidthProperty().bind(window.widthProperty());
background.fitHeightProperty().bind(window.heightProperty());
//startknop
Image startButtonShadow = new Image(getClass().getResourceAsStream("/images/start_button.png"));
Image startButtonNoShadow = new Image(getClass().getResourceAsStream("/images/start_button_no_shadow.png"));
Button startKnop = new Button();
startKnop.setGraphic(new ImageView(startButtonShadow));
startKnop.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
{
getScene().setRoot(new KeuzeSpelers());
}
});
gridPaneStart.add(startKnop, 1, 1);
//op scherm tonen
this.getChildren().addAll(background, gridPaneStart);
最佳答案
不,目前无法在 JavaFX CSS 中使用媒体查询。
仍有一个问题未解决:https://bugs.openjdk.java.net/browse/JDK-8091994
来自CSS Reference :
Beginning with JavaFX 8u20, the CSS @import is also partially supported. Only unconditional import is supported. In other words, the media‑type qualifier is not supported.
关于java - 是否可以向 JavaFX 添加媒体查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49897028/