JavaFX nodes. How to make them resizable by the end user?

I am developing a JavaFX application where the class I developed (extended from javafx.scene.Parent) is created on the fly based on the record that the user clicked on the ListView control.

To be clear about this node, it is not created using a layout tool such as SceneBuilder, it is created at runtime based on user actions.

The constructor for my custom node class creates a VBox and Label and uses the passed coordinates (X, Y) in the constructor method to set its own layout layouts. Then I use a special utility class to drag the node. This new node is then added to the main application panel.

However, I was not able to figure out how I can change these nodes by the user. That is, allow the user to mouse over the corner of the node, hold and drag to resize. An operation that all users are used to, no matter which OS.

Has anyone done something like this in JavaFX? (My searches on the subject only seem to be pulling up objects when automatically resizing, which the parent node does with its child nodes.)

Thank you very much,

Yang.

+6
source share
1 answer

As you can see in the VBox documentation , you can only determine the minimum, preferred, and maximum range, in fact there is no way to do this manually by resizing.

The only right solution to solve your problem is to develop your own class to do this, because what you want seems very specific with a description of the problem, I don’t think that using some layouts or panels will do what you definitely want.

I found what you can use: Drag and drop to resize JavaFX area

This allows you to resize the region, all you have to do is put VBox in this region, but pay attention to this article:

Currently, only resizing is implemented.

This code will not work in JavaFX8, you will need to check the comment to find out how it works in JavaFX8

Hope this helps.

0
source

Source: https://habr.com/ru/post/955030/


All Articles