是否可以向JavaFX添加媒体查询?

时间:2018-04-18 10:11:27

标签: java css javafx

我想知道是否可以在javafx中使用媒体查询。我有一个按钮,它是一个gridpane中的图像,当我为我的应用程序使用另一个分辨率时,gridpane适应新的分辨率,但按钮,即图像,不适应。

代码:

//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);

1 个答案:

答案 0 :(得分:1)

不,目前无法在JavaFX CSS中使用媒体查询。

仍然存在问题:https://bugs.openjdk.java.net/browse/JDK-8091994

来自CSS Reference

  

从JavaFX 8u20开始,CSS @import也是部分的   支持的。仅支持无条件导入。换句话说,   不支持media-type限定符。