Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9169329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:51:27+00:00 2026-06-17T15:51:27+00:00

I’m using swing to display multiple javafx Tableview , each embeded (thanks to JFXPanel

  • 0

I’m using swing to display multiple javafx Tableview, each embeded (thanks to JFXPanel) in a swing TabbedPane

I use the well know pattern described in the oracle doc, in scala way :

implicit def fun2Run[T](x: ⇒ T) = new Runnable {
    def run = x
  }

  def myTabbedScene():Scene = {
    val root = new StackPane
    root.getChildren.add(new Label("Hello world!"))
    new Scene(root, 300, 300)
  }

  def initFxPanel(fxPanel: JFXPanel, s: ⇒ Scene) = {
    fxPanel.setScene(s)
  }

  def initSwingGui(panel: PluginPanel) = {
    val fxPanel = new JFXPanel()
   // code to add panel to JPanel
    panel.peer.add(fxPanel)
    Platform runLater initFxPanel(fxPanel,myTabbedScene())
  }

  val jfxSwingPanel = new PluginPanel("wrap 2") {
    var jtemp = new JPanel()
    contents += jtemp
  }

  SwingUtilities invokeLater initSwingGui(jfxSwingPanel)

This code is executed each time the user open a new swing tab (only scene method differs) but i’m not sure this is the best way to manage thread in this case :-/

When i close or open a tab, i have some incoherent state in my application and error during display.

An example of my use case, and somes questions linked :

  • I open a first tab J1, a runlater is invoked, my scene display without problem in the tab.

  • I open a second tab J2, a new runlater is invoked on javafx Thread,

  • I switch to tab J1, how display in my tab is refresh ? An implicit runnable action is launched to main thread to make this possible ? How javafx recognized the good tab to refresh ? If i have a button which launch some action, i launch a runlater() action on the javafx main thread which dispatch ?

Update:

I find a code source which can help reader on this point, you can revalidate() or/and repaint() your swing panel (here _contentpane) which contain your jfxPanel

   SwingUtilities.invokeLater(new Runnable() { 
    public void run() { 
    _contentPane.add(_jfxPanel); 
    _contentPane.revalidate(); 
    _contentPane.repaint(); }});
  • I close the first tab J1, javafx automaticly close/garbage the javafx resource associated?

I have multiples other general questions :

  • How javafx application main thread manage this multiple runlater() call
    when they arrive from different jfxpanel in swing ?

  • How can i close properly the resources (without close main javafx thread with exit() Platform method) associated to my jfxpanel when user close a tab ? If i destroy the JFXPanel,javafx resources used to display are liberated ?

  • Using task to manage my thread can be an answer to my problem ?

My question are probably naive, but i start in gui building, and i have problem to understand how javafx manage scene on different embedded panel.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:51:28+00:00Added an answer on June 17, 2026 at 3:51 pm

    How javafx application thread manage this multiple runlater() call when they arrive from different jfxpanel in swing ?

    From the Platform.runLater javadoc:

    Run the specified Runnable on the JavaFX Application Thread at some
    unspecified time in the future. This method, which may be called from
    any thread, will post the Runnable to an event queue and then return
    immediately to the caller. The Runnables are executed in the order
    they are posted. A runnable passed into the runLater method will be
    executed before any Runnable passed into a subsequent call to
    runLater.

    Further:

    How can i close properly the thread (without close main javafx thread) which execute my jfxpanel when user close a tab?

    It’s unclear which thread you are referring to. In general, when integrating JavaFX and Swing there are only two threads to be concerned with – the Swing dispatch thread and the JavaFX application thread – both of which should be managed by the respective underlying frameworks and you don’t need to explicitly close. You don’t need any other threads unless you are trying to do something which should not execute on either of those threads (such as a highly CPU intensive task or a remote I/O) – which from your sample code would not be appear to be the case.

    Using task to manage my thread can be an answer to my problem ?

    Unless you have a specific need for such a thing, such a solution would likely further complicate your situation than improve it.

    I close the first tab J1, javafx automaticly close/garbage the javafx resource associated?

    If you don’t keep a reference to any of the resources in the related jfxpanel, then the Java Virtual Machine can garbage collect the jfxpanel and and resources associated with it – this is just standard Java garbage collection technology, nothing special here.

    I switch to tab J1, how display in my tab is refresh ? An implicit runnable action is launched to main thread to make this possible ?

    Sounds like a bad idea (the main thread in Java terms is the thread used to launch the Java’s main function and is not involved in GUI programming at all). You probably want to submit your runnable refresh request via Platform.runLater() so that it will be executed on the JavaFX application thread.

    How javafx recognized the good tab to refresh ?

    You have a JavaFX JFXPanel in each swing tab and each swing tab knows which JFXPanel it has, so when you invoke Platform.runLater to refresh the specific panel, pass a (final) reference to the JFXPanel to be used. Here is some psuedo-code in no language whatsoever to illustrate the concept:

    on swing tab change event
      final JFXPanel curPanel = tab.getJFXPanel()
      Platform.runLater() {
        // update curPanel here...
      }
    

    If i have a button which launch some action, i launch a runlater() action on the javafx main thread which dispatch ?

    In essence I think you are correct here, I’ll just rewrite your question to clarify some of the terminology – let’s say it’s a swing button and on performing an action on the swing button, you make a call to Platform.runLater, then the code in the runLater call will be eventually be executed on the JavaFX application thread.


    Other questions I cannot answer as I am not fluent enough in Scala to provide a reasonable answer.

    Honestly, if you are just starting GUI building, then my unsolicited advice would be to use Java rather than Scala and stick with either Swing or JavaFX, but not mix it all together until you are really comfortable with the GUI building process – otherwise there are just way too many traps and pitfalls you may encounter during the integration that few will be able to assist you with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am confused How to use looping for Json response Array in another Array.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.