【问题标题】:Issue to set textarea height to height of tab-content-size将 textarea 高度设置为 tab-content-size 高度的问题
【发布时间】:2018-04-26 13:29:05
【问题描述】:

我的问题是将textarea高度设置为tab-content-size,但是textarea只占用了一部分内容。

我尝试了不同的值作为 maxHeight-property 和 prefHeight 的 maxvalue,但没有成功。宽度没有问题,它适合标签内容。感谢您的帮助!

主程序:

public class Main extends Application {
    public static void main(String[] args) {
        Application.launch(Main.class, (java.lang.String[])null);
    } 
    @Override
    public void start(Stage primaryStage) {
        String resourcePath = "resources/fxml/ExampleFZ.fxml";
        URL location = Main.class.getResource(resourcePath);
        try {
            VBox page = (VBox) FXMLLoader.load(location);
            Scene scene = new Scene(page);
            primaryStage.setScene(scene);
            primaryStage.setTitle("Example FZ");
            primaryStage.show();            
        } catch(Exception ex)  {Logger.getLogger(Main.class.getName()).log(Level.SEVERE,null, ex);
        }
    }
}

FXML 代码:

<VBox fx:id="rootBox" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.ExampleFZcontroller">
<children>
  <GridPane>
    <columnConstraints>
      <ColumnConstraints hgrow="SOMETIMES" maxWidth="70.0" minWidth="70.0" prefWidth="70.0" />
      <ColumnConstraints hgrow="SOMETIMES" />
        <ColumnConstraints hgrow="SOMETIMES" />
    </columnConstraints>
    <rowConstraints>
      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    </rowConstraints>
     <children>
        <Button fx:id="myButton" mnemonicParsing="false" onAction="#myButtonClicked" text="Button" GridPane.halignment="CENTER" />            
     </children>
  </GridPane>
  <TabPane fx:id="myTabPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" tabClosingPolicy="UNAVAILABLE">
     <tabs>
        <Tab fx:id="myTab" text="MyTab">
           <content>
              <TextArea fx:id="myTextArea" maxHeight="1.7976931348623157E308" text="myText" />
           </content></Tab>
     </tabs></TabPane>
</children>
<stylesheets>
  <URL value="@../css/ExampleFZ.css" />
</stylesheets>
</VBox>

控制器代码:

public class ExampleFZcontroller {
    @FXML
    VBox rootBox;
    @FXML
    private Button myButton;
    @FXML
    private TabPane myTabPane;
    @FXML
    private Tab myTab;
    @FXML
    private TextArea myTextArea;    
    @FXML
    void myButtonClicked(ActionEvent event) {
        myTextArea.appendText("\nonce again");
    }
}

css 文件:

.tab-header-background {
   -fx-background-color: grey ;                             
.text-area  {
   -fx-border-width: 5px;
   -fx-border-color: red ;
}[enter image description here][1]

这是结果(见图):

【问题讨论】:

    标签: javafx textarea fxml


    【解决方案1】:

    文本区域正在填充选项卡的内容;问题是当窗口增大时选项卡窗格没有增长。您可以使用VBox 布局约束vgrow 解决此问题:

    <TabPane fx:id="myTabPane" VBox.vgrow="ALWAYS" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" tabClosingPolicy="UNAVAILABLE">
        <tabs>
            <Tab fx:id="myTab" text="MyTab">
                <content>
                    <TextArea fx:id="myTextArea" maxHeight="1.7976931348623157E308" 
                         text="myText" />
                </content>
             </Tab>
         </tabs>
    </TabPane>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-14
      • 2017-10-18
      • 2020-10-18
      • 1970-01-01
      • 2012-05-14
      相关资源
      最近更新 更多