我的问题是将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]
这是结果(见图):
答案 0 :(得分:0)
文本区域正在填写标签的内容;问题是当窗口增加大小时,选项卡窗格不会增长。您可以使用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>