I’m trying to retrieve the widthProperty of my parent column to assign it to my label but I can’t.
Without Split Column is ok
And with Split column widthProperty not working
I manage to recover those of the others simple column. In this exemple I want to get Name column Parent widthProperty.
Main code
package test;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Test extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
FXML Code
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<ScrollPane fitToHeight="true" fitToWidth="true" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1" fx:controller="test.MainController">
<content>
<VBox prefHeight="398.0" prefWidth="598.0">
<children>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children>
<TextArea fx:id="lb_Paper" prefHeight="200.0" promptText="Paper" wrapText="true" />
<TextArea fx:id="lb_PC" prefHeight="200.0" promptText="PC" wrapText="true" />
<TextArea fx:id="lb_Name" prefHeight="200.0" promptText="Complete Name" wrapText="true" />
<TextArea fx:id="lb_Movies" prefHeight="200.0" promptText="Movies" wrapText="true" />
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<children>
<TableView fx:id="tb_test" prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS">
<columns>
<TableColumn fx:id="column_Paper" prefWidth="75.0" text="Paper" />
<TableColumn fx:id="column_PC" prefWidth="75.0" text="PC" />
<TableColumn fx:id="column_Name" prefWidth="75.0" text="Name" />
<TableColumn fx:id="column_Movies" prefWidth="75.0" text="Movies" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</HBox>
</children>
</VBox>
</content>
</ScrollPane>
FXMLController Code
package test;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
public class MainController implements Initializable {
@FXML
private TextArea lb_Paper;
@FXML
private TextArea lb_PC;
@FXML
private TextArea lb_Name;
@FXML
private TextArea lb_Movies;
@FXML
private TableView<?> tb_test;
@FXML
private TableColumn<?, ?> column_Paper;
@FXML
private TableColumn<?, ?> column_PC;
@FXML
private TableColumn<?, ?> column_Name;
@FXML
private TableColumn<?, ?> column_Movies;
@Override
public void initialize(URL url, ResourceBundle rb) {
TableColumn firstactivitePedaCol = new TableColumn("First Name");
TableColumn secondactivitePedaCol = new TableColumn("Last Name");
column_Name.getColumns().addAll(firstactivitePedaCol, secondactivitePedaCol);
tb_test.setPlaceholder(new Label("Contexte"));
lb_Paper.prefWidthProperty().bind(column_Paper.widthProperty());
lb_Paper.minWidthProperty().bind(column_Paper.widthProperty());
lb_Paper.maxWidthProperty().bind(column_Paper.widthProperty());
lb_PC.prefWidthProperty().bind(column_PC.widthProperty());
lb_PC.minWidthProperty().bind(column_PC.widthProperty());
lb_PC.maxWidthProperty().bind(column_PC.widthProperty());
lb_Name.prefWidthProperty().bind(column_Name.widthProperty());
lb_Name.minWidthProperty().bind(column_Name.widthProperty());
lb_Name.maxWidthProperty().bind(column_Name.widthProperty());
lb_Movies.prefWidthProperty().bind(column_Movies.widthProperty());
lb_Movies.minWidthProperty().bind(column_Movies.widthProperty());
lb_Movies.maxWidthProperty().bind(column_Movies.widthProperty());
}
}
Thx in advance for your reply