package com.celertech.web.orderrouting.client; import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.embed.swing.JFXPanel; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.ContextMenu; import javafx.scene.control.MenuItem; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.stage.WindowEvent; import javafx.util.Callback; import javax.swing.JFrame; import javax.swing.SwingUtilities; import com.celertech.web.orderrouting.client.formatters.table.cell.LongFormatCell; public class TestClassWithJFXEmbeddedIntoSwing { /** * Creates a new instance of {@link TestClassWithJFXEmbeddedIntoSwing}. */ public TestClassWithJFXEmbeddedIntoSwing() { } private void initAndShowGUI() { // This method is invoked on the EDT thread JFrame frame = new JFrame("Swing and JavaFX"); final JFXPanel fxPanel = new JFXPanel(); frame.add(fxPanel); frame.setSize(300, 200); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Platform.runLater(new Runnable() { @Override public void run() { initFX(fxPanel); } }); } private void initAndShowGUIInJFX() { Stage stage = new Stage(); stage.setResizable(true); stage.setScene(createScene()); stage.show(); } private void initFX(JFXPanel fxPanel) { // This method is invoked on the JavaFX thread Scene scene = createScene(); fxPanel.setScene(scene); } public static Scene createScene() { Group root = new Group(); Scene scene = new Scene(root, Color.ALICEBLUE); TableColumn orderIdCol = new TableColumn("id"); orderIdCol.setCellValueFactory(new PropertyValueFactory("id")); orderIdCol.setSortable(true); orderIdCol.setPrefWidth(130); TableView table = new TableView(); ObservableList data = FXCollections.observableArrayList(); table.setItems(data); table.setTableMenuButtonVisible(true); ContextMenu tableMenu = new ContextMenu(); tableMenu.getItems().add(new MenuItem("Cancel")); table.setContextMenu(tableMenu); ObservableList> columns = table.getColumns(); columns.add(orderIdCol); root.getChildren().add(table); data.add(new TableRow(1, "scott")); table.getContextMenu().setOnShowing(new EventHandler() { @Override public void handle(WindowEvent arg0) { System.out.println("test"); } }); return scene; } public static void main(String[] args) { final JFXPanel fxPanel = new JFXPanel(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { TestClassWithJFXEmbeddedIntoSwing testClassWithJFXEmbeddedIntoSwing = new TestClassWithJFXEmbeddedIntoSwing(); testClassWithJFXEmbeddedIntoSwing.initAndShowGUI(); } }); } public static class TableRow { private final long id; private final String name; /** * Creates a new instance of {@link TableRow}. */ public TableRow(long id, String name) { this.id = id; this.name = name; } /** * @return the id */ public long getId() { return this.id; } /** * @return the name */ public String getName() { return this.name; } } }