Skip to content
Advertisement

Animate adding components to a pane

I want to implement some kind of notification system in my application but I have trouble with the calculation of the actual position of my notification. All notifications should appear in a separate stage and each notification should be aligned among themselves and each notification is a simple VBox with two labels (title and message).

I created a little standalone application with the issue I have.

As soon as you press the button on the main stage, a VBox will be created and added to a second notification stage. As soon as a seconds notification needs to be added, this second notification should be below the first notification and so on. Therefore I need to find the height of the first notification in order to position the second notification underneath.

I know I could use a VBox instead, but in my application the notification should make a smooth animation and push the other notifications further down. I removed the whole animation and removing part of notifications so the example stays as small as possible.

The problem is that all notification boxes have the same height – but they don’t (if you modify the text and make it longer / smaller).

JavaScript

I used the ScenicView Tool to verify the height and it says that the height is 79, but the System.out tells me the height is 10.4. The 79 value seems to be correct, but how can I get this value in my application?

enter image description here

Advertisement

Answer

The short answer is use applyCss():

JavaScript

From the documentation:

If required, apply styles to this Node and its children, if any. This method does not normally need to be invoked directly but may be used in conjunction with Parent.layout() to size a Node before the next pulse

The long and better answer is to use a VBox or a ListView.

To add layout animation use LayoutAnimator.java. You can find more details here.

Edit: an mre of using LayoutAnimator to animate newly added notifications:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement