I am just trying out JavaFX and am forcing my way into it because it is suppose to be the future. I am trying to create a table with 4 columns. The columns AND THE TABLE should resize to fill the parent pane. I cannot for the life of me get this to work. I have been trying for over 4 hours now and the tableview does not resize.
Here is my FXML file.
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import java.net.*?>
<?import javafx.geometry.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.collections.*?>
<?import t.cubed.fxml.*?>
<BorderPane styleClass="root" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="t.cubed.fxml.FXMLDocumentController">
<top>
<MenuBar fx:id="menuBar" styleClass="menu-bar">
<menus>
<Menu text="File">
<items>
<MenuItem onAction="#handleOpenAction" text="Open" />
<MenuItem onAction="#handleExitAction" text="Exit" />
</items>
</Menu>
<Menu text="Edit">
<items>
<MenuItem onAction="#handleWeightAction" text="Edit Weights" />
<MenuItem onAction="#handleFilterAction" text="Edit Filters" />
<MenuItem onAction="#handleOptionsAction" text="Options" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<center>
<GridPane>
<!--
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
-->
<TableView fx:id="testTable" GridPane.columnIndex="0" GridPane.rowIndex="0" GridPane.columnSpan="1">
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<columns>
<TableColumn text="TEST NUMBER">
<cellValueFactory>
<PropertyValueFactory property="testNumber" />
</cellValueFactory>
</TableColumn>
<TableColumn text="TEST NAME">
<cellValueFactory>
<PropertyValueFactory property="testName" />
</cellValueFactory>
</TableColumn>
<TableColumn text="TEST TIME(ms)">
<cellValueFactory>
<PropertyValueFactory property="testTime" />
</cellValueFactory>
</TableColumn>
<TableColumn text="BEST MATCH">
<cellValueFactory>
<PropertyValueFactory property="bestMatch" />
</cellValueFactory>
</TableColumn>
</columns>
<items>
<!--
<FXCollections fx:factory="observableArrayList">
<TestTableModel testNumber="100" testName="Test1234" testTime="0.34" bestMatch="99"/>
</FXCollections>
-->
</items>
</TableView>
</GridPane>
</center>
<stylesheets>
<URL value="#t-cubed.css" />
</stylesheets>
</BorderPane>
How Resizable Layout Works
The size of resizable items in JavaFX is managed by the layout managers in which the items are placed.
What you need to do
For your particular issue, you need to set the GridPane sizing constraints to manage the TableView that you placed in the grid.
See the GridPane.hgrow and GridPane.vgrow constraints I added on the TableView:
<TableView fx:id="testTable"
GridPane.columnIndex="0"
GridPane.columnSpan="1"
GridPane.hgrow="ALWAYS"
GridPane.vgrow="ALWAYS"
GridPane.rowIndex="0">
FXML just reflects the Java API, so you could also do the same in Java source as well; i.e. GridPane.setHGrow(node, priority). Though, if you are using FXML for your layout, defining the layout constraints in FXML is recommended.
Refactored Sample
I loaded your FXML up in Scene Builder 2 and set the appropriate constraints and it appears to resize automatically fine when I use the preview functionality of Scene Builder.
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import java.net.*?>
<?import javafx.geometry.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.collections.*?>
<?import t.cubed.fxml.*?>
<BorderPane styleClass="root" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="t.cubed.fxml.FXMLDocumentController">
<top>
<MenuBar fx:id="menuBar" styleClass="menu-bar">
<menus>
<Menu text="File">
<items>
<MenuItem onAction="#handleOpenAction" text="Open" />
<MenuItem onAction="#handleExitAction" text="Exit" />
</items>
</Menu>
<Menu text="Edit">
<items>
<MenuItem onAction="#handleWeightAction" text="Edit Weights" />
<MenuItem onAction="#handleFilterAction" text="Edit Filters" />
<MenuItem onAction="#handleOptionsAction" text="Options" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<center>
<GridPane>
<children>
<!--
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
-->
<TableView fx:id="testTable" GridPane.columnIndex="0" GridPane.columnSpan="1" GridPane.hgrow="ALWAYS" GridPane.rowIndex="0" GridPane.vgrow="ALWAYS">
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<columns>
<TableColumn text="TEST NUMBER">
<cellValueFactory>
<PropertyValueFactory property="testNumber" />
</cellValueFactory>
</TableColumn>
<TableColumn text="TEST NAME">
<cellValueFactory>
<PropertyValueFactory property="testName" />
</cellValueFactory>
</TableColumn>
<TableColumn text="TEST TIME(ms)">
<cellValueFactory>
<PropertyValueFactory property="testTime" />
</cellValueFactory>
</TableColumn>
<TableColumn text="BEST MATCH">
<cellValueFactory>
<PropertyValueFactory property="bestMatch" />
</cellValueFactory>
</TableColumn>
</columns>
<items>
<!--
<FXCollections fx:factory="observableArrayList">
<TestTableModel testNumber="100" testName="Test1234" testTime="0.34" bestMatch="99"/>
</FXCollections>
-->
</items>
</TableView>
</children>
<columnConstraints>
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
</rowConstraints>
</GridPane>
</center>
<stylesheets>
<URL value="#t-cubed.css" />
</stylesheets>
</BorderPane>
Some Advice
You are placing the TableView inside a GridPane. Using a GridPane in your case is a little strange as the GridPane you only place one node in the GridPane. Just placing the TableView directly in the center of your BorderPane or using a simpler layout parent such as a StackPane would have worked just fine. But perhaps this is just some cut down version of a more complex UI, so perhaps that is why you have used a GridPane.
Further Reading
If you have time, read up on layout in JavaFX in the Node, Pane, Group and GridPane javadoc and try this little layout bounds demo too.
Additional Questions for Comments
mention a StackPane would work, but StackPanes don't seem to have Hgrow and Vgrow?
StackPanes don't need a Hgrow or Vgrow constraints. Those constraints set Priorities, which are defined as:
Enumeration used to determine the grow (or shrink) priority of a given
node's layout area when its region has more (or less) space available
and multiple nodes are competing for that space.
With a StackPane, all children are layered on top of each other, they don't compete for space, so such growth priority settings for child nodes are not applicable.
After some homework, we came up with some qualifying information on FXML containers. Pretty much for the same reason given above by #user3403469. In the Scene Builder, there's a long list of 'containers'. Imho, only these 9 elements and Pane qualify as layout container, as they inherit from
<Pane> ... parent for all Pane classes. While both, Pane and Control inherit from Region only the Pane child-classes have layout properties.
* <AnchorPane>
* <BorderPane>
* <FlowPane>
* <GridPane>
* <StackPane>
* <TextFlow>
* <TilePane>
* <HBox>
* <VBox>
You can consider that Control child-classes more or less inherit Events and actions. Layout like things need to come from the encapsulating region, and the only thing with layout elements available to wrap a 'Control' is-a 'Pane'.
javafx.scene.layout.Pane
These FXML elements would be the bespoke 'layout managers' described in the #jewelsea's answer and elsewhere.
I guess 'Control' containers are still containers in FXML. It seems that they need to be 'inside' a panel to do good ;-)
Corrections and comment welcome.
related:
Percent width for TableColumn in JavaFX 2.x TableView
There seems to be a lot of code. My idea of dynamic resizing is a Zero-tolerance for code to do scaling and resize. Gee we left that behind in Windows 1.3 didn't we?
where is the: FXML Specification?
Reference and Guidelines for Dynamic Layout using JavaFX
Related
I'm finding the way that how to bind the size of a pane with the outer pane.
I could bind the size ofRectangle with Pane,
But couldn't bind an inner pane (Red dotted rectangle) with outer pane (Blue dotted rectangle)
Why I couldn't do it
It seems to be that Pane does not provide bind method for widthProperty
Objects
At least, bind width with TextArea of inner Pane with outer Pane
I'll make many new tabs, therefore, I prefer to bind inner Pane with outer Pane rather than bind TextArea directly to outer Pane.
Situation
Blue and Orange rectangles are bound well with pane dropPane
But Blue border pane's width should be the same size as a red border pane!
My Sources
main.kt:
import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene.*
import javafx.scene.control.*
import javafx.scene.paint.Paint
import javafx.scene.shape.Rectangle
import javafx.stage.Stage
import javafx.scene.layout.*
import javafx.scene.paint.*
fun main(args : Array<String>) {
println("EntryPoint")
Application.launch(PaneBindingTest().javaClass, *args)
}
class PaneBindingTest : Application() {
private var tabCount = 0
private fun generateNewTab (): Tab {
val tab = Tab()
tabCount += 1
tab.text = "Tab$tabCount"
val fxml = javaClass.getResource("fxml/Tab.fxml")
val aTabPane: Pane = FXMLLoader.load(fxml)
aTabPane.border = Border(BorderStroke(Paint.valueOf("Red"),BorderStrokeStyle.DASHED, CornerRadii.EMPTY, BorderWidths.DEFAULT))
tab.content = aTabPane
return tab
}
override fun start(primaryStage: Stage) {
primaryStage.title = "EntryPoint"
primaryStage.isAlwaysOnTop = true
val fxml = javaClass.getResource("fxml/EntryPoint.fxml")
val root: Parent = FXMLLoader.load(fxml)
val scene = Scene(root)
val epPane= root.lookup("#EPPane") as AnchorPane // Entry Point Pane
val dropPane= root.lookup("#DropPane") as AnchorPane // Drop Pane
val tabPane= root.lookup("#TabPane") as TabPane // Tab Pane
val singleDropPoint= root.lookup("#ForSingle") as Rectangle // Single-ArchiveSet drop point
val multiDropPoint = root.lookup("#ForMulti") as Rectangle // Multi-ArchiveSet drop point
//epPane.background = Background(BackgroundFill(Paint.valueOf("Yellow"), CornerRadii(0.0), Insets(0.0,0.0,0.0,0.0)))
//dropPane.background = Background(BackgroundFill(Paint.valueOf("Green"), CornerRadii(0.0), Insets(0.0,0.0,0.0,0.0)))
tabPane.tabClosingPolicy = TabPane.TabClosingPolicy.ALL_TABS // or SELECTED_TAB, UNAVAILABLE
tabPane.border = Border(BorderStroke(Paint.valueOf("Blue"),BorderStrokeStyle.DASHED, CornerRadii.EMPTY, BorderWidths.DEFAULT))
singleDropPoint.heightProperty().bind(epPane.heightProperty().divide(32).multiply(23))
multiDropPoint.yProperty().bind(singleDropPoint.yProperty().add(dropPane.heightProperty().divide(4).multiply(3)))
multiDropPoint.heightProperty().bind(epPane.heightProperty().divide(4))
primaryStage.scene = scene
primaryStage.show()
val newTab = generateNewTab()
tabPane.tabs.add(newTab)
tabPane.selectionModel.select(newTab)
}
}
fxml/EntryPoint.fxml
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.shape.Rectangle?>
<AnchorPane fx:id="EPPane" prefHeight="640.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TabPane fx:id="TabPane" prefHeight="640.0" prefWidth="1152.0" tabClosingPolicy="ALL_TABS" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="128.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
</TabPane>
<AnchorPane fx:id="DropPane" layoutY="128.0" maxWidth="128.0" minWidth="128.0" prefWidth="128.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Rectangle fx:id="ForSingle" arcHeight="16.0" arcWidth="16.0" fill="DODGERBLUE" height="360.0" width="120.0" stroke="#1100ff" strokeType="INSIDE" strokeWidth="8.0" AnchorPane.leftAnchor="4.0" AnchorPane.rightAnchor="4.0" AnchorPane.topAnchor="4.0"/>
<Rectangle fx:id="ForMulti" arcHeight="16.0" arcWidth="16.0" fill="#ff9d1f" height="240.0" width="120.0" stroke="#ff8800" strokeType="INSIDE" strokeWidth="8.0" AnchorPane.leftAnchor="4.0" AnchorPane.rightAnchor="4.0" AnchorPane.bottomAnchor="4.0"/>
</children>
</AnchorPane>
</children>
</AnchorPane>
fxml/Tab.fxml:
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TextArea fx:id="FilePaths" layoutX="4.0" layoutY="80.0" prefHeight="128.0" AnchorPane.leftAnchor="4.0" AnchorPane.rightAnchor="4.0" AnchorPane.topAnchor="72.0" />
<RadioButton layoutX="14.0" layoutY="206.0" mnemonicParsing="false" selected="true" text="Hash/Size only">
<toggleGroup>
<ToggleGroup fx:id="AnalyzeMethod" />
</toggleGroup>
</RadioButton>
<RadioButton layoutX="120.0" layoutY="206.0" mnemonicParsing="false" text="FileName" toggleGroup="$AnalyzeMethod" />
<RadioButton layoutX="200.0" layoutY="206.0" mnemonicParsing="false" text="Directory Structure" toggleGroup="$AnalyzeMethod" />
<CheckBox fx:id="CheckDiff" layoutX="336.0" layoutY="206.0" mnemonicParsing="false" text="Show Diff" />
<CheckBox fx:id="CheckSame" layoutX="420.0" layoutY="206.0" mnemonicParsing="false" text="Show Same" />
<ComboBox fx:id="ComboBox" layoutX="840.0" layoutY="202.0" prefWidth="150.0" />
<HBox fx:id="LabelBox" layoutX="12.0" layoutY="14.0" prefHeight="64.0" prefWidth="978.0" AnchorPane.leftAnchor="4.0" AnchorPane.rightAnchor="4.0" AnchorPane.topAnchor="4.0" />
</children>
</AnchorPane>
I've found that almost the same question, but no answer was there.
You do not need a binding to achieve this. The problem is the fact that you set the constraints for maxHeight/maxWidth to USE_PREF_SIZE, i.e. to a fixed value that can very well be reached when resizing the window. Remove those constraints to allow the AnchorPane to grow as necessary:
Tab.fxml
<AnchorPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
...
</AnchorPane>
Furthermore I recommend avoiding the use of AnchorPanes, if you can avoid it. It's hard to achieve responsive layouts with this kind of layout. VBox and HBox would do much better jobs in this case.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.Region?>
<VBox prefHeight="480.0"
prefWidth="1000.0" xmlns="http://javafx.com/javafx/10.0.1"
xmlns:fx="http://javafx.com/fxml/1">
<padding>
<Insets topRightBottomLeft="4" />
</padding>
<children>
<HBox fx:id="LabelBox" prefHeight="64.0" prefWidth="978.0" />
<TextArea VBox.vgrow="ALWAYS" fx:id="FilePaths"
prefHeight="128.0">
</TextArea>
<HBox spacing="10" minWidth="-Infinity">
<VBox.margin>
<Insets top="5" left="0" right="0" bottom="0" />
</VBox.margin>
<children>
<RadioButton mnemonicParsing="false" selected="true"
text="Hash/Size only">
<toggleGroup>
<ToggleGroup fx:id="AnalyzeMethod" />
</toggleGroup>
</RadioButton>
<RadioButton mnemonicParsing="false" text="FileName"
toggleGroup="$AnalyzeMethod" />
<RadioButton mnemonicParsing="false"
text="Directory Structure" toggleGroup="$AnalyzeMethod" />
<CheckBox fx:id="CheckDiff" mnemonicParsing="false"
text="Show Diff" />
<CheckBox fx:id="CheckSame" mnemonicParsing="false"
text="Show Same" />
<Region HBox.hgrow="ALWAYS" /> <!-- placeholder to grow/shrink -->
<ComboBox fx:id="ComboBox" prefWidth="150.0" />
</children>
</HBox>
</children>
</VBox>
I need some help. How do you center a text in HBox. I am using SceneBuilder. I try and I can't figure it out how to do it.
Here is the code for FXML.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.geometry.Point3D?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Text?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<top>
<HBox prefHeight="50.0" prefWidth="800.0" BorderPane.alignment="CENTER">
<children>
<Text boundsType="LOGICAL_VERTICAL_CENTER" layoutX="600.0" layoutY="600.0" scaleZ="0.0" strokeType="OUTSIDE" strokeWidth="0.0" text="GIANTS DATABASE" textAlignment="CENTER" textOrigin="CENTER" wrappingWidth="231.7841796875" x="600.0" y="600.0">
<rotationAxis>
<Point3D x="1.0" y="1.0" z="1.0" />
</rotationAxis>
</Text>
</children></HBox>
</top>
<right>
<TableView prefHeight="550.0" prefWidth="577.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn minWidth="0.0" prefWidth="72.0" text="Rank" />
<TableColumn editable="false" minWidth="0.0" prefWidth="206.0" text="Name" />
<TableColumn editable="false" minWidth="0.0" prefWidth="88.0" text="Position" />
<TableColumn minWidth="0.0" prefWidth="77.0" text="School" />
<TableColumn minWidth="0.0" prefWidth="66.0" text="Age" />
<TableColumn minWidth="0.0" prefWidth="66.0" text="War" />
</columns>
</TableView>
</right>
<opaqueInsets>
<Insets />
</opaqueInsets>
<padding>
<Insets bottom="3.0" right="3.0" />
</padding>
The text I want to center is GIANTS DATABASE, under HBox children
Here is the code for javaFX
public class Login extends Application {
#Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("/giants/LoginF.fxml"));
Scene scene = new Scene(root);
primaryStage.setTitle("Giants Database Login");
primaryStage.setScene(scene);
primaryStage.show();
}
catch (Exception e) {
}
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Here is the image of the text *GIANTS DATABASE. And I want to center the text where the arrow is pointing**
Remove the bounds, layoutX/Y and rotation settings on the Text node - they are not needed for this. What you are looking for is the HBox alignment property - setting it to Pos.CENTER will layout the children of the HBox in the center both vertically and horizontally. If you want to keep it to the left use Pos.CENTER_LEFT.
It is also not clear from your question whether you wish for the HBox to be this tall - it may be helpful to change the prefHeight of the HBox to Region.USE_COMPUTED_SIZE to have it match the size of the Text note (plus any padding/margins set on either of them).
since the ListView seems to have some visual bugs when it comes to storing items with a different cell size (resulted in duplicated entries #displaying), I decided to try out a ScrollPane. I replaced the ListView with a ScrollPane with a inner VBox (there are custom HBox stored). So long it's working fine, I dont get any visual bugs any more.
Now I just have a simple problem: As soon the ScrollPane is "full" and starts scrolling, it seems to adjust the size of my "bigger" items.
Here a screen how it looks before the resizing:
Here a screen how it looks when the resize starts:
Here is the fxml of my custom HBox:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<fx:root type="javafx.scene.layout.HBox" fx:id="hboxGridContainer" maxHeight="Infinity" maxWidth="Infinity" prefWidth="580.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" alignment="CENTER_LEFT" styleClass="theme-presets inbox-entry">
<children>
<GridPane fx:id="gridPaneMessages" prefWidth="350.0">
<columnConstraints>
<ColumnConstraints fillWidth="true" hgrow="ALWAYS" />
<ColumnConstraints hgrow="SOMETIMES" />
</columnConstraints>
<rowConstraints>
<RowConstraints fillHeight="true" vgrow="ALWAYS" />
</rowConstraints>
<children>
<HBox fx:id="hboxMessage" alignment="TOP_LEFT" maxHeight="Infinity" minWidth="191.0">
<children>
<Label fx:id="labelMessage" alignment="TOP_LEFT" maxHeight="Infinity" minWidth="191.0" text="blablubkeks" wrapText="true" />
</children>
</HBox>
<AnchorPane GridPane.columnIndex="1">
<children>
<ImageView fx:id="imageViewEncrypted" fitHeight="33.0" fitWidth="33.0" layoutX="43.0" layoutY="-2.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../../images/key.png" />
</image>
</ImageView>
<ImageView fx:id="imageViewSigned" fitHeight="42.0" fitWidth="33.0" layoutX="80.0" layoutY="-2.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../../images/doublecheck.png" />
</image>
</ImageView>
<Label fx:id="labelTime" layoutX="4.0" layoutY="6.0" prefHeight="17.0" prefWidth="76.0" text="Label" />
</children>
</AnchorPane>
</children>
</GridPane>
</children>
</fx:root>
Here is an extract of my ScrollPane usage in fxml:
<ScrollPane fx:id="scrollPaneChat" layoutX="14.0" layoutY="14.0">
<content>
<VBox fx:id="chatWindowListView" prefHeight="531.0" prefWidth="607.0" />
</content>
</ScrollPane>
The official documentation states, the ScrollPane fitToHeight Property is default on false, which should prevent resizing my HBox's. I want the HBox to stay at it's original height.
Please help me.
Pic of the TableView header
I need help aligning the headers for the columns on this TableView. The problem seems to be related to setting the TableView's column resize policy to constrained-resize. Can someone explain how to fix this? Thanks.
I am setting the policy to constrained-resize to get rid of the extra column based on this SO post: TableView has more columns than specified
My stack: Java 8, JavaFX 8, and scenebuilder
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane maxHeight="200.0" maxWidth="322.0" prefHeight="200.0" prefWidth="320.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1">
<center>
<TableView fx:id="statusTable" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="322.0">
<columns>
<TableColumn fx:id="statusDescription" minWidth="120.0" prefWidth="210.0" text="Description" />
<TableColumn fx:id="status" prefWidth="97.0" text="Priority" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</center>
</BorderPane>
I'm using NetBeans and SceneBuilder to make a JavaFX GUI. My question is among the three files (the FXML, the controller, and the java file) what do I need to do to make the width of my menubar expand when the user expands the stage (or anchor pane, please also educate me on the proper term)?
Thanks!
~Bricks
I figured out what I was doing wrong, thanks to ItachiUchiha's comment. I was originally using AnchorPane as my root layout but switched to HBox so that I could use the hgrow property.
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<HBox>
<children>
<MenuBar HBox.hgrow="ALWAYS">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</children>
</HBox>