Peter Penzov
Peter Penzov

Reputation: 1668

Resize table size

I created a table insight FlowPane.

flowPane.widthProperty().addListener(new ChangeListener()
{
    @Override
    public void changed(ObservableValue ov, Object t, Object t1)
    {
        double value = (double) t1;
        table.setPrefSize(value, 600);
        System.out.println("Scene Width :" + value);
    }
});

I want when I resize the main stage and also the FlowPane also to resize the size of the table. I created this listener which takes the FlowPane size. But when I resize the the main stage the table size is not changed. Can you help me what I'm missing?

Upvotes: 0

Views: 151

Answers (1)

Brendan
Brendan

Reputation: 3649

Since you are only updating the width of the table in the changed method of your listener I'm going to assume that you only want the table to grow/shrink horizontally. Assuming this is the case, I would suggest that rather than setting up a ChangeListener, you try setting up a unidirectional binding between the width properties of the the FlowPane and the TableView.

table.prefWidthProperty().bind(flowPane.widthProperty());

The binding ensures that anytime the flowPane's widthProperty changes, the table's prefWidthProperty will also be updated. If you wish to continue using the ChangeListener, you can avoid casting the new value as follows...

flowPane.widthProperty().addListener(new ChangeListener<Number>()
{
    @Override
    public void changed(ObservableValue ov, Number t, Number t1)
    {
        table.setPrefSize(t1.doubleValue(), 600);
        System.out.println("Scene Width :" + t1.doubleValue());
    }
});

Hope this answer is helpful!

Upvotes: 1

Related Questions