• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Java FX related to Swing

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jim Clarke, Jim Connors & Eric J. Bruno,

How does Java FX programming model differ from Swing?

Can you mix and match Swing and Java FX components?

Is Java FX multi-threaded or do you have a similar issue of the event-dispatch thread?

Best regards,

Alan Dickinson
 
author
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaFX has 3 platform profiles, Desktop, Mobile, and TV. Swing only is supported on the Desktop.

JavaFX supports JavaFX versions of several of Swing components contained in the javafx.ext.Swing package.
Ready made components are available for SwingButton(JButton), SwingCheckBox(JCheckBox),
SwingComboBox(JComboBox), SwingIcon(Icon), SwingLabel(JLabel), SwingList(JList),
SwingRadioButton(JRadioButton), SwingScrollPane(JScrollPane), SwingSlider(JSlider),
SwingTetField( JTextField ), and SwingToggleButton(JToggleButton).

You can also create your own javafx Swing classes by either wrapping the JComponent using
the javafx.ext.swing.SwingComponent.wrap() function as in:

var myComponent = SwingComponent.wrap(myJComponent);

Another way is to have your JavaFX class extend SwingComponent and implement
the abstract funciton, protected abstract createJComponent() : javax.swing.JComponent.

Personally, I try to shy away from the Swing classes and use the javafx.scene.control classes. That way my application
can run on all three platforms.
 
Jim Clarke
author
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaFX is single threaded similar to Swing and you can only update JavaFX objects
on the main JavaFX thread. In the JavaFX language there is no support for creating
threads or doing synchronization semantics.

Usually, the only reason you have to get on to the main JavaFX thread is you
have java code that is running in its own thread and you need to communicate
back to the JavaFX environment.

From java, there is a class:



If you want to do something like the Swing invokeLater call from JavaFX,
there is a function in javafx.lang.FX called deferAction. It works like this:

;

If you want to do an asynchronous task you need to use the javafx.async classes. I have done a write up
on this at my blog: http://blogs.sun.com/clarkeman/
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package application;  
import javafx.application.Application;  
importjavafx.scene.control.Button;  
import javafx.stage.Stage;  
public class Hello_World extends Application{  
 
   @Override  
   public void start(Stage primaryStage) throws Exception {  
       // TODO Auto-generated method stub  
       Buttonbtn1=newButton("Say, Hello World");  
         
   }  
 
}  
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic