簡體   English   中英

使用JFXDecorator時組件不會自動調整大小,如何解決?

[英]Components won't auto-resizing when using JFXDecorator, how to fix that?

我想使用JFXDecorator來看看我的應用程序的窗口。 但使用它會破壞組件的自動調整大小。 這就是我的代碼

 @Override
 public void start(Stage stage) throws Exception {

    FXMLLoader loader = new FXMLLoader(getClass().getResource("ApplicationView.fxml"));
    Parent root = loader.load();

    JFXDecorator decorator = new JFXDecorator(stage, root);
    decorator.setCustomMaximize(true);

    stage.setTitle("Weather API");
    stage.setScene(new Scene(decorator));

    String cssURI = getClass().getResource("stylesheet/style.css").toExternalForm();
    decorator.getStylesheets().add(cssURI);

    stage.show();
}

這就是效果,看看分割窗格。

窗戶壞了

沒有JFXDecorator可以正常使用下面的代碼。

@Override
public void start(Stage stage) throws Exception {

    FXMLLoader loader = new FXMLLoader(getClass().getResource("ApplicationView.fxml"));
    Parent root = loader.load();

    stage.setTitle("Weather API");
    stage.setScene(new Scene(root));

    String cssURI = getClass().getResource("stylesheet/style.css").toExternalForm();

    stage.show();
}

作品

我試圖設置主窗格的AncorPane屬性類似於孩子,所以它可能會重新啟動,但它失敗了。 我的FXML看起來像那樣

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>


<AnchorPane AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="640.0" stylesheets="@stylesheet/style.css" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.161">
   <children>
     <SplitPane dividerPositions="0.29797979797979796" layoutX="220.0" layoutY="129.0" prefHeight="480.0" prefWidth="640.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
      <items>
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
      </items>
    </SplitPane>
   </children>
</AnchorPane>

我該如何解決? 謝謝。

擺脫AnchorPane並使SplitPane成為根節點。

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>

<SplitPane dividerPositions="0.29797979797979796" prefHeight="480.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1">
   <items>
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
   </items>
</SplitPane>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM