0
我想向我的JavaFX8應用程序添加java.awt.Panel
。不幸的是,似乎小組在附加到SwingNode
時沒有被呈現。AWT Panel未在JFX中呈現
我有一個簡單testapplication:包含java.awt.Panel
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Panel;
import javax.swing.JPanel;
public class AWTPanel extends JPanel{
public AWTPanel()
{
Dimension d = new Dimension(600, 400);
setPreferredSize(d);
Panel p = new Panel();
p.setSize(d);
p.setPreferredSize(d);
p.setBackground(Color.red);
this.add(p);
this.setBackground(Color.green);
}
}
其他AWT組件不露面
import java.awt.Dimension;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class AWTInJFX extends Application {
@Override
public void start(Stage stage) {
final AwtInitializerTask awtInitializerTask = new AwtInitializerTask(() -> {
AWTPanel panel = new AWTPanel();
return panel;
});
SwingNode swingNode = new SwingNode();
SwingUtilities.invokeLater(awtInitializerTask);
try {
swingNode.setContent(awtInitializerTask.get());
} catch (InterruptedException | ExecutionException ex) {
Logger.getLogger(AWTInJFX.class.getName()).log(Level.SEVERE, null, ex);
}
stage.setScene(new Scene(new Group(swingNode), 600, 600));
stage.setResizable(false);
stage.show();
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame();
frame.setSize(new Dimension(600, 400));
frame.add(new AWTPanel());
frame.setVisible(true);
});
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
private class AwtInitializerTask extends FutureTask<JPanel> {
public AwtInitializerTask(Callable<JPanel> callable) {
super(callable);
}
}
}
我的JPanel要麼當我加我AWTPanel到SwingNode。
有人可以解釋爲什麼這不起作用嗎?
我需要一個AWT面板來獲得在附加C++庫中使用的hWnd。
不幸的是,它看起來好像我必須在我的應用程序中使用Swing/AWT和'JFXPanel'。 – Rikan 2015-04-02 11:28:44