Reputation: 18120
I'm using fxml in JavaFX and I want a list master/detail view. A list on the left of a fixed size, and a detail of a TextArea where the width grows with the window size.
This is my fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<top>
<MenuBar prefWidth="671.0" BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<center>
<HBox BorderPane.alignment="CENTER">
<children>
<ListView prefHeight="754.0" prefWidth="236.0" />
<TextArea />
</children>
</HBox>
</center>
</BorderPane>
This sample fxml looks like this:
You can see that the list is correct, and the textArea is showing and growing in height but not in width.
EDIT
Modified due to an answer.
This is the full code now. I only changed the max width and height of -Infinity to -1 but still no luck.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<BorderPane maxHeight="-1" maxWidth="-1" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<top>
<MenuBar prefWidth="671.0" BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<center>
<HBox BorderPane.alignment="CENTER">
<children>
<ListView prefHeight="754.0" prefWidth="236.0" />
<TextArea />
</children>
</HBox>
</center>
</BorderPane>
Upvotes: 0
Views: 3591
Reputation: 209330
Set the HBox.hgrow
property of the text area:
<TextArea HBox.hgrow="ALWAYS"/>
Upvotes: 5
Reputation: 6911
The value of negative infinity is the constant USE_PREF_SIZE, which means your BorderPane
will never be larger than its preferred size (which in your case is 1280x800).
Changing the maximum width and height to USE_COMPUTED_SIZE (-1) should solve your problem. As this is the default value, you could just remove the maxHeight
and maxWidth
attributes.
Upvotes: 0