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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| package test;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.scenicview.ScenicView;
public class Main2 extends JFrame implements Initializable {
@FXML
private Parent root;
public Main2() {
// This method is invoked on the JavaFX thread (see main, the thread which loaded the FXML).
super("MyFame");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void initialize(URL location, ResourceBundle resources) {
// This method is invoked on the JavaFX thread
final Scene scene = new Scene(root);
final JFXPanel host = new JFXPanel();
host.setScene(scene);
ScenicView.show(scene);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// This method is invoked on the EDT.
setContentPane(host);
setSize(500, 500);
setVisible(true);
}
});
}
public static void main(String... args) {
// Only needed to the test case, initializes JFX toolkit.
new JFXPanel();
Platform.runLater(new Runnable() {
public void run() {
try {
// This method is invoked on the JavaFX thread (not sure it is needed).
final String fxmlPath = "test.fxml";
final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(fxmlPath));
fxmlLoader.load();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
//ouvre popup
@FXML
private void handleOpenTerminMngt() throws IOException {
// This method is invoked on the JavaFX thread
createModalDialog("Mon Titre", new FXCreator() {
@Override
public void run() {
initFX(jfxPanel);
}
});
}
private final JFXPanel jfxPanel = new JFXPanel();
private void createModalDialog(String title, FXCreator creator) {
if (!SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// This method is invoked on the EDT.
createModalDialog(title, creator);
}
});
return;
}
// This part of the method is invoked on the EDT.
final JDialog dialog = new JDialog();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
final JButton btnOk = new JButton("Ok");
// btnOk = IconButtonFactory.getButton(myConstants.BTN_OK);
btnOk.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
// This method is invoked on the EDT.
dialog.setVisible(false);
}
});
btnOk.setSize(50, 50);
final JPanel btnBar = new JPanel(new BorderLayout(5, 0));
btnBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
btnBar.add(btnOk, BorderLayout.EAST);
dialog.setLayout(new BorderLayout());
dialog.add(jfxPanel, BorderLayout.CENTER);
dialog.add(btnBar, BorderLayout.SOUTH);
dialog.setPreferredSize(new Dimension(600, 600));
dialog.setTitle(title);
dialog.setModal(true);
dialog.setAlwaysOnTop(true);
dialog.pack();
dialog.setLocationRelativeTo(this);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
// This method is invoked on the EDT.
if (creator != null) {
Platform.runLater(creator);
}
}
});
dialog.setVisible(true);
}
private void initFX(final JFXPanel host) {
// This method is invoked on the JavaFX thread
try {
final String fxmlPath = "TerminCrud.fxml";
final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(fxmlPath));
final Parent root = (Parent) fxmlLoader.load();
final Scene scene = new Scene(root, 255, 255);
host.setScene(scene);
} catch (IOException e) {
e.printStackTrace();
}
}
} |
Partager