A perfect java blog

FIFO and LIFO in javafx

20 May,2011Narayan G. Maharjan

If you really interested to keep the nodes in a group with your custom order like LIFO(Last In First Out) or FIFO(First In First Out then it’s easy from javafx with the help of javafx keyword insert , into, before.

Nodes on a Group in FILO(First In Last Out) order. I mean the updated nodes will be at the index [0] and old one nodes would just swap to index[1] and so on.
Here what i’m going to start via NetBeans 6.5.1

Create a JavaFX Project with name whatever you want. Then ya you will see a default Stage with some imports.

For LIFO:

Let’s move to upwards and code some stuff as shown below:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

//....imports

varmyBox=javafx.scene.layout.VBox{

spacing:5layoutY:30

}

varsubmit=javafx.scene.control.Button{

layoutX:150

text:"Submit"

action:function(){

insert javafx.scene.text.Text{

x:1y:30

content:input.text

}into myBox.content

}

}

varinput=javafx.scene.control.TextBox{

columns:12

selectOnFocus:true

}

//....Stage declaration

Output:

Output LIFO

In above code i modified to insert new Node i.e. Text in VBox before first element index(as 0). So there is no any surprise on codes it’s like a human language. That’s all now your application runs in FILO order.

For FILO

Now let’s move to FILO order I mean updated records just comes on first or just inverse than we did before. You don’t need to change whole code just modify some stuff codes as below:

1

2

3

4

5

6

7

8

9

10

11

varsubmit=javafx.scene.control.Button{

layoutX:150

text:"Submit"

action:function(){

insert javafx.scene.text.Text{

x:1y:30

content:input.text

}before myBox.content[0]

}

}

Output:

Output FILO

In above code i modified to insert new Node i.e. Text in VBox before first element index(as 0). So there is no any surprise on codes it’s like a human language. That’s all now your application runs in FILO order.