Skip to content

doug-rocha/JavaFX-Components

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NonaCept JavaFX Components

GitHub release License

Some JavaFX components for making your life easier.


InternalWindow

com.nonacept.javafx.scene.layout.InternalWindow is similar to JInternalWindow from Swing.

It extends Pane and can be added to any Parent, allowing content to be added inside a "window within a window". You can move, resize, and maximize it.


How to use

For this example, I will assume you already know a bit of JavaFX and have a Pane ready to be used as a "Desktop":

Create the InternalWindowManager

InternalWindowManager iwm = InternalWindowManager
        .create()
        .managing(contentPanel);

After this the object iwm can be used to manage the creation of InternalWindow.
You can create windows with:

  • createInternalWindow → multiple instances allowed.
  • createUniqueInternalWindow → only one instance; focuses if called again. (Note: the uniqueness is based on the type Class)
iwm.createUniqueInternalWindow("/example.fxml",
                mainStage,
                ExampleController.class,
                customInitConsumer
);

Parameters:

Parameter Description
/example.fxml Location of the FXML file
mainStage Main Stage (can be null)
ExampleController.class Your FXML controller implementing InternalWindowContent (also used to manage the uniqueness)
customInitConsumer Custom code to run on initialization

Note: every parameter passed when creating the InternalWindowManager will be used for all InternalWindow created by it.


Optional: Global Initializer

InternalWindowInitializer<ExampleController> initializer = (controller, stage, internalWindow) -> {
    controller.doSomething(stage);
    controller.alsoDoThis(internalWindow);
};

InternalWindowManager iwm = InternalWindowManager
        .create()
        .managing(contentPanel)
        .withInitializer(initializer);

The global initializer code, will be executed when creating a InternalWindow.
As you may see the initializer must be a implementation of InternalWindowInitializer with a controller type as parameter.
Note: if you intend to use InternalWindows with multiple types of controllers, define a more generic Controller class to be used here and extend by the actual Controllers, or use a customInitConsumer for every Window, as the InternalWindow creation example.


Optional: Listener & Theme

You can provide an Object that implements ChildListener in order to receive calls when the InternalWindow opens or closes; a InternalWindow.Theme can also be passed:

InternalWindowManager iwm = InternalWindowManager
        .create()
        .managing(contentPanel)
        .withListener(this)                             // listens to open/close
        .defaultTheme(InternalWindow.Theme.NONACEPT);   // set theme

Currently available themes: JAVAFX and NONACEPT.


Complete Example

InternalWindowInitializer<ExampleController> initializer = ((controller, stage, internalWindow) -> {
            controller.doSomething(stage);
            controller.alsoDoThis(internalWindow);
        });

InternalWindowManager iwm = InternalWindowManager
        .create()
        .managing(contentPanel)
        .withListener(this)
        .withInitializer(initializer)
        .defaultTheme(InternalWindow.Theme.NONACEPT);

iwm.createUniqueInternalWindow("/example.fxml", mainStage, ExampleController.class, customInitConsumer);
iwm.createInternalWindow("/example.fxml", mainStage, customInitConsumer);

Screenshots

Click the images to enlarge:

Move Maximize Resize

About

Some JavaFX components for making your life easier

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published