Internal Frames in JavaFX


Question

I found this example of Internal Frames

http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html

Is it possible to make the same internal Frames in JavaFX?

1
6
7/16/2013 9:49:17 AM

With JFXtras there is a Window control, where you can add content and handle the internal window behavior.

First you will need to put in your classpath the jfxtras library. They have some instructions where you can get the library. If you are using maven, just need to add:

<dependency>
    <groupId>org.jfxtras</groupId>
    <artifactId>jfxtras-labs</artifactId>
    <version>2.2-r5</version>
</dependency>

Or download the library and put it into your project classpath, whatever.

Now I put a sample of the demo of the Window with a little difference, allowing generation of several windows.

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import jfxtras.labs.scene.control.window.CloseIcon;
import jfxtras.labs.scene.control.window.MinimizeIcon;
    import jfxtras.labs.scene.control.window.Window;


public class WindowTests extends Application {
private static int counter = 1;

private void init(Stage primaryStage) {
    final Group root = new Group();

    Button button = new Button("Add more windows");     

    root.getChildren().addAll(button);
    primaryStage.setResizable(false);
    primaryStage.setScene(new Scene(root, 600, 500));

    button.setOnAction(new EventHandler<ActionEvent>() {            
        @Override
        public void handle(ActionEvent arg0) {
            // create a window with title "My Window"
            Window w = new Window("My Window#"+counter);
            // set the window position to 10,10 (coordinates inside canvas)
            w.setLayoutX(10);
            w.setLayoutY(10);
            // define the initial window size
            w.setPrefSize(300, 200);
            // either to the left
            w.getLeftIcons().add(new CloseIcon(w));
            // .. or to the right
            w.getRightIcons().add(new MinimizeIcon(w));
            // add some content
            w.getContentPane().getChildren().add(new Label("Content... \nof the window#"+counter++));
            // add the window to the canvas
            root.getChildren().add(w);  
        }
    });
}

public double getSampleWidth() {return 600;}
public double getSampleHeight() {return 500;}

@Override
public void start(Stage primaryStage) throws Exception {
    init(primaryStage);
    primaryStage.show();


}
    public static void main(String[] args) {launch(args);}
}

In the original demo, the event code was in the init method, and no button was included. I add the button to create dynamically windows and adding them to the screen.

Here is a snapshot of the result of the application:

snapshot

I totally recommend you try the demo of jfxtras. They have really great stuff. Hope it helps.

11
7/17/2013 7:42:04 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon