How to Use ‘CardLayout’ like Panel with JRebirth StackModel

The StackModel class will do the job (provided by org.jrebirth.af:component artifact), you can find 2 usages here and here.

Each ‘card’ model can be called using a enum|modelKey identifier, and each stack has an unique name.

The first sample is used for the JRebirth Demo Application, it’s a pretty simple application that will allow to display other JRebirth showcase applications dynamically loaded as JRebirth module (from a separate and independent jar).

JRebirth Demo Application Main Class

Java

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

publicfinalclassJRebirthDemoextendsDefaultApplication<StackPane>{

publicstaticvoidmain(finalString...args){

Application.launch(JRebirthDemo.class,args);

}

@Override

publicClass<?extendsModel>firstModelClass(){

returnMainModel.class;

}

@Override

protectedStringapplicationTitle(){

return"JRebirth Demo Application";

}

@Override

protectedvoidcustomizeScene(finalScene scene){

super.customizeScene(scene);

addCSS(scene,DemoStyles.DEFAULT);

addCSS(scene,WorkbenchStyles.DEFAULT);

}

@Override

protectedvoidcustomizeStage(finalStage stage){

// Center the stage

stage.centerOnScreen();

}

@Override

protectedList<?extendsResourceItem<?,?,?>>getResourceToPreload(){

returnCollections.emptyList();

}

}

This application will load its first model (MainModel) and put its root node into the scene root node (StackPane, automatically built).The MainModel will list all application’s sub modules to add a button entries into its left menu, and a StackModel that will display each module content. The StackModel is loaded using special annotation using its unique String key.