Reputation: 53
My issue is to set the textarea height to the tab-content-size, but the textarea takes only a part of the content.
I tried different values as maxvalue for maxHeight-property and prefHeight, but no success. There's no problem with the width, its fits the tab-content. Thanks for your help!
The main program:
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);
}
}
}
The FXML-Code:
<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>
The Controller-Code:
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");
}
}
The css-file:
.tab-header-background {
-fx-background-color: grey ;
.text-area {
-fx-border-width: 5px;
-fx-border-color: red ;
}[enter image description here][1]
this is the result (see the image):
Upvotes: 1
Views: 491
Reputation: 209684
The text area is filling the tab's content; the problem is that the tab pane is not growing when the window increases size. You can fix this with the VBox
layout constraint 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>
Upvotes: 1