Mixing JavaFX with Swing in different windows
Kevin Rushforth
kevin.rushforth at oracle.com
Tue Apr 24 08:53:28 PDT 2012
> I wonder if http://javafx-jira.kenai.com/browse/RT-15011 can help
with removing/re-adding a JFXPanel.
The same mechanism could be used, but will likely need additional API on
JFXPanel (since there is no Application instance, and since in the case
of Swing Inerop it is the JFXPanel that needs to manage the life-cycle
to meet Swing's needs).
-- Kevin
Anthony Petrov wrote:
> I wonder if http://javafx-jira.kenai.com/browse/RT-15011 can help with
> removing/re-adding a JFXPanel. JIRA is down currently, but here's some
> details:
>
> http://mail.openjdk.java.net/pipermail/openjfx-dev/2012-April/001202.html
>
> --
> best regards,
> Anthony
>
> On 4/24/2012 7:24 PM, Jeff Martin wrote:
>> I have had general success with this - the only real trick I think is
>> to create/modify your JavaFX scene from Platform.runLater(), which is
>> a little bit of a dance. Below is some code that is working for me.
>>
>> The exception is that that when I remove the JFXPanel, then try to
>> re-install it later, I get an exception along the lines of
>> "Platform.exit() has already been called", which I think happens when
>> JavaFX figures out that there is no more visible JavaFX UI.
>>
>> jeff
>>
>>
>> On Apr 24, 2012, at 9:04 AM, Josh Marinacci wrote:
>>
>>> Has anyone had luck building an app with one window that is Swing
>>> and the other is JavaFX? I want to slowly moving my large app
>>> (LeonardoSketch.org) over to JavaFX.
>>> I have built a new window in JavaFX but I get some init errors on
>>> startup. Instead I can put the FX content inside of a JXPanel, but
>>> many things break on the FX side like drag and drop. I would rather
>>> run the FX content in a real FX stage. I am fine having one window
>>> be run on the FX thread and one on the Swing thread with me being
>>> responsible for synchronization via invokeLater calls. I'm
>>> wondering if there is any magic init-mojo required.
>>>
>>> Thanks
>>> Josh
>>
>> /**
>> * Returns the JavaFX panel.
>> */
>> public JFXPanel getJavaFXPanel()
>> {
>> // If panel not set, create and set
>> if(_jfxPanel==null) {
>> _jfxPanel = new JFXPanel();
>> Platform.runLater(new Runnable() { public void run() {
>> initFX(); }});
>> }
>> // Return panel
>> return _jfxPanel;
>> }
>>
>> /**
>> * Load JavaFX panel.
>> */
>> private void initFX()
>> {
>> // This method is invoked on the JavaFX thread
>> Scene scene = getScene();
>> _jfxPanel.setScene(scene);
>> // Add to Swing panel
>> SwingUtilities.invokeLater(new Runnable() { public void run() {
>> _contentPane.add(_jfxPanel);
>> _contentPane.revalidate(); _contentPane.repaint();
>> }});
>> }
>>
More information about the openjfx-dev
mailing list