Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am developing a JavaFX application where a class I have developed (extended from javafx.scene.Parent) is created on-the-fly based on what entry the user has clicked in a ListView control.

Just to be clear about this node, it is not created using a layout tool like SceneBuilder, it is created at runtime based on the user's actions.

The constructor for my custom node class creates a VBox and a Label and uses passed coordinates (X,Y) in the constructor method to set its own Layout coords. I then use a custom utility class to make the node draggable. This new node is then added to the main application Pane.

However, I have failed to find out how I can make these nodes resizable 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 what the OS.

Has anyone done anything like this in JavaFX? (My searches on the subject only seem to pull up subjects on the automatic resizing that a parent node does with its child nodes.)

Many thanks,

Ian.

like image 203
Cladgeman Avatar asked Oct 01 '13 14:10

Cladgeman


1 Answers

As you can see on the documentation of VBox you can only define minimum, prefered and maximum range, there's not really a way to make it manually resizable.

The only proper solution to solve your problem is to develop your own class to do it, because what you want seems very specific, with your problem description, I don't think use some layouts or panels will do what you exactly want.

I found something that you can use : Dragging to resize a JavaFX Region

This allows you to resize a region, all you have to do after is to put you VBox in this region, but notice in this article that :

Only height resizing is currently implemented.

This code won't work in JavaFX8, you'll have to check the comment to see how it worls in JavaFX8

Hope this helps.

like image 110
Evans Belloeil Avatar answered Oct 15 '22 10:10

Evans Belloeil