JavaFX / Swing Integrated : Swing « JavaFX « Java






JavaFX / Swing Integrated

 

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Main {
  private static void initAndShowGUI() {
    final JFrame frame = new JFrame("JavaFX / Swing Integrated");
    final JFXPanel fxPanel = new JFXPanel();
    frame.add(fxPanel);
    frame.setVisible(true);

    Platform.runLater(new Runnable() {
      @Override
      public void run() {
        initFX(fxPanel);
      }
    });
  }

  private static void initFX(JFXPanel fxPanel) {
    final Group rootGroup = new Group();
    final Scene scene = new Scene(rootGroup, 800, 400, Color.BEIGE);

    fxPanel.setScene(scene);
  }

  public static void main(String[] arguments) {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        initAndShowGUI();
      }
    });
  }
}

   
  








Related examples in the same category

1.JavaFx and Swing