JavaFX compared to Swing

Hi All
I am trying to work with new JavaFX, I got an experience with Swing, with my first impression it seems that controls like Dialog, messageBox, internalFrame, Frame, Dialog, are not there, maybe because this is the way to make the new RIA looks like web sites, but what are the controls instead of these Swing controls?
Shlomo.

There are no specific replacements if you are looking for things like what JOptionPane provided.. you have to build your own dialog with a Stage.

Similar Messages

  • JavaFX Canvas : "fuzzy" lines compared to Swing

    Hi,
    I would very much like to port my Swing application (that draws on a JComponent) to JavaFX. But to my dismay the JavaFX Canvas does not draw as sharp and thin lines as Swing does.
    Lines drawn with the same thickness is noticeably thicker (and "fuzzier") on the JavaFX Canvas than the equivalent Swing lines. I have tested both on Windows (7) and Linux, both 64-bit.
    In my JavaFX app, I proceed like this: gc.beginPath() --> gc.moveTo(..) --> gc.lineTo() --> gc.stroke().
    Is there a setting or something I am missing?

    You need to take into account the coordinate system.
    For further explanation of why this works see the answer to the question below and Node's javadoc:
    http://stackoverflow.com/questions/11881834/what-are-a-lines-exact-dimensions-in-javafx-2
    http://docs.oracle.com/javafx/2/api/javafx/scene/Node.html
    At the device pixel level, integer coordinates map onto the corners and cracks between the pixels and the centers of the pixels appear at the midpoints between integer pixel locations. Because all coordinate values are specified with floating point numbers, coordinates can precisely point to these corners (when the floating point values have exact integer values) or to any location on the pixel. For example, a coordinate of (0.5, 0.5) would point to the center of the upper left pixel on the Stage. Similarly, a rectangle at (0, 0) with dimensions of 10 by 10 would span from the upper left corner of the upper left pixel on the Stage to the lower right corner of the 10th pixel on the 10th scanline. The pixel center of the last pixel inside that rectangle would be at the coordinates (9.5, 9.5).
    import javafx.application.Application;
    import javafx.scene.*;
    import javafx.scene.canvas.*;
    import javafx.stage.Stage;
    /** JavaFX Canvas : "fuzzy" lines compared to Swing JavaFX Canvas : "fuzzy" lines compared to Swing */
    public class FuzzyCanvas extends Application {
      public static void main(String[] args) { launch(args); }
      @Override public void start(Stage stage) {
        Canvas canvas = new Canvas(50, 50);
        GraphicsContext gc = canvas.getGraphicsContext2D();
        gc.beginPath();    // fuzzy line.
        gc.moveTo(10, 30);
        gc.lineTo(20, 30);
        gc.stroke();
        gc.beginPath();    // clean line.
        gc.moveTo(10.5, 39.5);
        gc.lineTo(19.5, 39.5);
        gc.stroke();
        stage.setScene(new Scene(new Group(canvas)));
        stage.show();
    }

  • JavaFX embedded into Swing applications - success

    For those of you who are trying to use JavaFX within Swing here is an easy way to do it.
    Rectangle rect = new Rectangle();
    rect.$width.setAsDouble(100);
    rect.$height.setAsDouble(100);
    SGNode sgNode = rect.getSGRectangle();
    JSGPanel sgPanel = new JSGPanel();
    sgPanel.setScene(sgNode);
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(sgPanel, BorderLayout.CENTER);The same approach also works for custom nodes you have developed yourself. Note that you can change values of public variables declared in your JavaFX node with e.g. rect.$width.setAsDouble(200.0); When you do this be sure you run the value update code from event dispatch thread.
    I guess this makes JavaFX more usable for us who develop desktop applications with Swing and can't start rewriting everything in JavaFX :-)
    Edited by: aless on Dec 12, 2008 6:51 AM

    aless,
    can you provide concrete example of your approach. im new to fx really unable to follow your example. I tried to follow pmd's explanation but im unable to load the fx classes by the same class loader. Im getting the following error in the runtime
    Thanks and appreciate your help.
    Sri
    Exception in thread "main" java.lang.ClassNotFoundException: test.TestFx
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at test.TestJavaFX.main(TestJavaFX.java:27)
    Profiler Agent: Initializing...
    package test;
    import com.sun.scenario.scenegraph.JSGPanel;
    import com.sun.scenario.scenegraph.SGNode;
    public class TestJavaFX {
    public static void main(String[] args) throws Exception {
    Class c = Class.forName("test.TestFx");
    TestFxInterface test = (TestFxInterface) c.newInstance();
    SGNode sgNode = test.getSGNode();
    JSGPanel sgPanel = new JSGPanel();
    sgPanel.setScene(sgNode);
    package test;
    import com.sun.scenario.scenegraph.SGNode;
    import javafx.scene.CustomNode;
    import javafx.scene.Group;
    import javafx.scene.Node;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Circle;
    import javafx.scene.shape.Rectangle;
    public class TestFx extends CustomNode, TestFxInterface {
    public override function create(): Node {
    return Group {
    content: [
    Rectangle {
    x: 10,
    y: 10
    width: 140,
    height: 90
    fill: Color.BLACK
    Circle {
    centerX: 100,
    centerY: 100
    radius: 40
    fill: Color.BLUE
    public override function getSGNode(): SGNode {
    return
    this.impl_getSGNode();
    package test;
    import com.sun.scenario.scenegraph.SGNode;
    public interface TestFxInterface {
    public SGNode getSGNode();
    }

  • JavaFX equivalent of Swing JComboBox.KeySelectionManager for ChoiceBox?

    Does ChoiceBox have any built-in key selection functionality as was provided by KeySelectionManager to JComboBox?
    If so, could someone provide an example?
    Else, anyone else think this would be worth a feature request? As a user, I really like being able to tab through choice boxes and just hit a key or two to make my selections as opposed to mousing and scrolling through all the items.

    I am also wondering a typical structure of application framework on java fx. Where will the screens be defined and created? How is an operational flow implemented? A simple login form with onSuccess, onError with sufficient redirections will be very helpful. I mean a crud skeleton based on common api of javafx will be a perfect guide.

  • For my requirements: javafx or swing?

    Hello, I'm starting a project in java.
    The application will be Desktop. Will run in a computer, and will not have internet-acess.
    The application will not require special effects or something like. It will just read and write in a data base. But it must have a good user interface.
    I wish to make this application using javafx, instead of swing or awt.
    Is worth to create this application in javafx? Or I'll get the same results, for my requeriments, that if I use swing?
    Thanks.

    Hi.
    Your persistence must be implemented in java because javafx doesn´t have a DB API yet. Probably your logic/model classes will too. So, no choice.
    About the gui, remember that actually javafx doesn´t have all controls used in typical crud applications (e.g. combobox and table). So, You´ll have to import them from java swing. The javafx declarative gui programming model allows You to implement guis easy and fast but If your gui is not complex and don´t need to be sophisticated I think It´s not a big advantage. Layout in javafx is much better in version 1.2 but, depending on your guis requirements, It still lacks a gridbaglayout-like solution.
    Do a little spike or prototype to help You compare and decide. ;-)
    Cheers

  • Embedding JavaFX v1.2 Scene's in Swing

    Before I start... SUN DOES NOT SUPPORT THIS AND IT IS LIKELY TO CHANGE... hopefully we get official support in a future release, please :)
    +"Note: We also recognize the need for the inverse (embedding a JavaFX scene into a Swing app), however that is not supported with 1.2 as it requires a more formal mechanism for manipulating JavaFX objects from Java code. The structure of these JavaFX objects is a moving target (for some very good reasons) and we're not ready to lock that down (yet). However,as with most software, this can be hacked (see Rich & Jasper's hack on Josh's blog) but know that you are laying compatibility down on the tracks if you go there. "+ Source: http://weblogs.java.net/blog/aim/archive/2009/06/insiders_guide.html
    But if you really really want this now read on.
    After a lengthy investigation and some help from others (including the jfxtra's project) here is how to Embed a JavaFX scene in your Swing application:
    First, start your java application with javafx and not java! This will fix any potential class path issues and really does solve a lot of issues you will have 'patching' the JVM with JavaFX (if that is even possible). JavaFX will happily run a Java project (with the JVM) even if there is not one JavaFX class in your project.
    Next, you need to create a Java Interface for your JavaFX object to implement:
    package mix.javastuff;
    * This is a Java Interface that your JavaFX class should implement.
    * This will define how Java will interact with your JavaFX class.
    * @author ahhughes
    public interface TextDisplay {
        public void setText(String text);
    }Next, you need to create your JavaFX object... it must extend Scene and you are to provide any interaction with Java you will need to implement a java interface:
    package mix.javafxstuff;
    import mix.javastuff.TextDisplay;
    import javafx.scene.Scene;
    import javafx.scene.text.Text;
    import javafx.scene.text.Font;
    import javafx.scene.effect.Reflection;
    import javafx.scene.text.TextOrigin;
    * Here is a very simple scene, that implements a java interface
    * That allows Java (or JavaFX) to setText on the Scene's content.
    public class TextDisplayJavaFXScene extends Scene , TextDisplay {
        override public function setText(text:String):Void{
            content = Text {
                    font : Font {size: 44}
                    x: 0, y: 0
                    textOrigin: TextOrigin.TOP
                    content: text
                    effect: Reflection {}
    }Finally, you need to use some reflection and some under the hood magic to get your JavaFX object and wrap in in a SwingScene (which just so happens to extend JComponent).
    package mix.javastuff;
    import com.sun.javafx.tk.swing.SwingScene;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javafx.reflect.FXClassType;
    import javafx.reflect.FXContext;
    import javafx.reflect.FXFunctionMember;
    import javafx.reflect.FXLocal;
    import javafx.reflect.FXLocal.ObjectValue;
    import javafx.scene.Scene;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    * Example of how to inject JavaFX into your Swing app.
    public class Main {
        private static final FXLocal.Context context = FXLocal.getContext();
        private static TextDisplay textDisplayJavaFXScene;// javafx scene & java interface
        public static void main(String[] args) {
            //Get the JavaFX Object, that has 'extends Scene, SomeJavaInterface'
         FXClassType instanceType = context.findClass("mix.javafxstuff.TextDisplayJavaFXScene");
         ObjectValue objectInstance = (ObjectValue) instanceType.newInstance();
         textDisplayJavaFXScene = (TextDisplay) objectInstance.asObject();
            //Wrap this in a SwingScene using refection
            JComponent textDisplayJavaFXSwingScene = sceneInstanceToJComponent((Scene)textDisplayJavaFXScene);
            //Now let's show the JComponent+JavaFXScene in a simple Swing App.
            createSimpleSwingApp(textDisplayJavaFXSwingScene);
         * This method wraps the Scene with a JComponent. This is what you can add
         * to your Swing application.
         * @param scene the JavaFX object that extends javafx.scene.Scene.
         * @return the javafx.scene.Scene wrapped by a JComponent.
         public static JComponent sceneInstanceToJComponent(Scene scene) {
             FXClassType sceneType = FXContext.getInstance().findClass("javafx.scene.Scene");
             ObjectValue obj = FXLocal.getContext().mirrorOf(scene);
             FXFunctionMember getPeer = sceneType.getFunction("impl_getPeer");
             FXLocal.ObjectValue peer = (ObjectValue) getPeer.invoke(obj);
             SwingScene swingScene = (SwingScene)peer.asObject();
             return (JComponent) swingScene.scenePanel;
         * OK, this method is just to show you this in action.... the real stuff
         * you are interested is in the methods above.
         * @param javaFXTextDisplaySwingScene
        private static void createSimpleSwingApp(JComponent javaFXTextDisplaySwingScene){
             JFrame frame = new JFrame();
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             frame.setSize(500,500);
             frame.setAlwaysOnTop(true);
              JPanel panel = new JPanel();
              panel.setLayout(new FlowLayout());
            //create a swing interface to interact with textDisplayJavaFXScene.setText()
            final JTextField textInputField = new JTextField("Set THIS Text!");
              panel.add(textInputField);
              JButton button = new JButton("Send to JavaFX!");
              panel.add(button);
              button.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e) {
                        textDisplayJavaFXScene.setText(textInputField.getText());
            //add the JavaFX SwingScene to the Swing's JPanel
             panel.add(javaFXTextDisplaySwingScene);
            //display the swing app
             frame.add(panel);
             frame.setVisible(true);
    }That's it!

    morningstar wrote:
    You can refer to this article for how to embeded javaFX scene into SWING:
    [JavaFX Scene embedded in SWING Window|http://www.javafxgame.com/javafx-scene-swing-java/]
    [http://www.javafxgame.com/javafx-scene-swing-java/|http://www.javafxgame.com/javafx-scene-swing-java/]
    Hi morningstar, this article is good and it too helped me out A LOT! It shows how to embed a JavaFX scene in swing but doesn't show you how to interact with JavaFX objects FROM your Java/Swing code. Wrapping the JavaFX node in a SwingScene doesn't offer a way for the Java/Swing code to interact with the underlying JavaFX objects.
    How can you set the text in the JavaFX Text node from the Java/Swing code in the linked article? You can't, all you can do is have the JavaFX objects reference BACK to public static fields in your Java code (not the best):
    Java Class:
    public class JavaFXToSwingTest extends JFrame {
        public static JTextField tf = new JTextField("JavaFX for SWING");
        //other code
    JavaFX Class:
        text = JavaFXToSwingTest.tf.getText();  On the other hand, the code in the first post exposes the JavaFX objects through java interfaces as well as wrapping them in a SwingScene. This means that you can do YourJavaFXObject.setText("Blah"); from inside your Java/Swing code, rather handy! :)
    Edited by: AndrewHughes on Jul 27, 2009 12:25 AM

  • No reply from JavaFX on WinApi User32.sendMessage HWND_BROADCAST

    Dear all,
    Problem
    what? 3rd party software communicates using the sendMessage function User32.dll with flag HWND_BROADCAST.
    when? as soon as they are used in combination with a JavaFX application the 3rd party applications crash.
    Our own investigation
    We fear that JavaFX fails(?) to respond (correctly?) to this WinApi call and hence the sendMessage broadcast is failing.
    Here is a stacktrace of such a 3rd party application (made with OllyDbg):
    CPU Stack
    Address   Value      ASCII Comments
    0018F8CC  /0000FFFF  ÿÿ    ; |hWnd = 0000FFFF
    0018F8D0  |0000C3AA  ªÃ    ; |Msg = 0C3AA
    0018F8D4  |000003E8  è    ; |wParam = 3E8
    0018F8D8  |0000C098  ˜À    ; \lParam = 0C098
    0018F8DC  \004859B0  °YH   ; RETURN from thirdparty.004859D8 to thirdparty.004859B0
    0018F8E0  /0018F900   ù   ; Pointer to next SEH record
    0018F8E4  |004859C6  ÆYH   ; SE handler
    0018F8E8  |0018F8F8  øø
    0018F8EC  |023BA998  ˜©;
    0018F8F0  |068BAC44  D¬‹  ; ASCII "C:\otherthirdparty"
    0018F8F4  |0000C098  ˜À
    0018F8F8  |0018F918  ù
    0018F8FC  \007461BA  ºat   ; RETURN from thirdparty.00485964 to thirdparty.007461BAAs you can see the hWnd parameter has value 0000FFFF or -1 or HWND_BROADCAST.
    CPU Disasm
    Address   Hex dump          Command                                  Comments
    004859D8  /$  52            PUSH EDX                                 ; /lParam => ARG.EDX
    004859D9  |.  0FB7C0        MOVZX EAX,AX                             ; |
    004859DC  |.  50            PUSH EAX                                 ; |wParam
    004859DD  |.  0FB705 B06F7A MOVZX EAX,WORD PTR DS:[7A6FB0]           ; |
    004859E4  |.  50            PUSH EAX                                 ; |Msg
    004859E5  |.  68 FFFF0000   PUSH 0FFFF                               ; |hWnd = 0000FFFF
    004859EA  |.  E8 4531F8FF   CALL <JMP.&user32.SendMessageA>          ; \USER32.SendMessageAThis is typically bad practise from ages ago, when interprocess communication was safe, back in the 16bit days.
    The third party applications at our clients appear to only crash systematically when running JavaFX applications next to them.
    JNA + Swing Code which should fix it
    public class JnaWinEvents extends JFrame {
         private static final long serialVersionUID = -3985408320174213410L;
         public LONG_PTR prevWndProc; // so it won't get GC'ed
         public WndProc wndProcCallbackListener = null; // so it won't get GC'ed
         public JnaWinEvents() {
              this.add(new JLabel("Hello StackExchange!"));
              this.pack();
              this.setVisible(true);
              setupEventsListener();
         public interface MyUser32 extends User32 {
              public static final MyUser32 MYINSTANCE = (MyUser32) Native.loadLibrary("user32", MyUser32.class, W32APIOptions.UNICODE_OPTIONS);
               * Changes an attribute of the specified window
               * @param hWnd
               *            A handle to the window
               * @param nIndex
               *            The zero-based offset to the value to be set.
               * @param callback
               *            The callback function for the value to be set.
              public LONG_PTR SetWindowLong(HWND hWnd, int nIndex, WndProc callback);
         public class WndProc implements StdCallCallback {
              public LRESULT callback(HWND hWnd, int uMsg, WPARAM wParam, LPARAM lParam) {
                   System.out.println("callback " + hWnd + "\t" + uMsg + "\t" + wParam.toString() + "\t" + lParam.toString());
                   return new LRESULT(0l);
         private void setupEventsListener() {
              HWND hWnd = new HWND();
              hWnd.setPointer(Native.getWindowPointer(this));
              this.wndProcCallbackListener = new WndProc();
              // Set the WndProc function to use our callback listener instead of the
              // window's one.
              LONG_PTR result = MyUser32.MYINSTANCE.SetWindowLong(hWnd, com.sun.jna.platform.win32.WinUser.GWL_WNDPROC, wndProcCallbackListener);
              System.out.println("setting my window proc, result = " + result);
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   @Override
                   public void run() {
                        new JnaWinEvents();
    }The code above should override the WndProc method of the view and hence fix the issue, obviously when using JavaFX instead of Swing.
    The code above is able to print the sendMessage requests - please not that only HWND_BROADCAST will make the application fail.
    IMPORTANT Swing does NOT crash like JavaFX - do NOT expect the code above to crash.
    Question?
    Is there any way to get the pointer from the JavaFX Window as we are doing now with the JFrame ?
    References
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx
    http://blogs.msdn.com/b/oldnewthing/archive/2006/06/13/629451.aspx
    http://msdn.microsoft.com/en-us/library/windows/desktop/dd744765(v=vs.85).aspx
    Tools
    We have simulated the behaviour by coding a simple application in C# which calls the sendMessage with HWND_BROADCAST
    When needed we can provide the source code - I did not find a way to attach files to this forum.

    >
    First, correct, we understand that going really deep in to the internals of JavaFX may cause issues in the long run. But unfortunately, because there is no current alternative, we are forced doing so.::PostMessage(HWND_BROADCAST, ...) looks like a reasonable choice. Couldn't you use it?
    Yes I read about the Glass Framework but was not able to find a way to override this WindowProc, most likely as you said due to visibility issues. Maybe you can guide me a bit further into actually being able to get to this Glass class, if it were only to extend my logs, it would be of great intellectual value to me.Glass, as well as Prism, is currently completely hidden for FX applications. Although you can access some of the classes from these libs, it will likely be impossible, once we have modules (e.g. Jigsaw) in place.
    We also know that JavaFX is far from the only application which is crashing on sendMessage(HWND_BROADCAST) calls. We did further testing and it appears even Google Chrome tends to crash, eg. when opening facebook or gmail the application sending HWND_BROADCAST will hang aswell. This actually surprised me, it Google Chrome only tends to crash the application when having certain websites opened. The hang doesn’t occur when having eg. www.google.com open.My own experiments show that we don't crash, but rather make the application that sens broadcast messages hang.
    •     Is the Glass team investigating this issue further in order to find a viable solution?See my comments to RT-23660.
    •     Can you provide me more insight to how the Glass Framework works
    o     More specified logging
    o     Tricks to manipulate the Framework
    o     Does and donts concerning finding a workaround combined with the Glass Framework
    Important extra information: Swing does not cause the sendMessage call to hang. As written above, AWT/Swing/Java2D vs Glass/Prism/JavaFX is like comparing apples to oranges :)
    As I wrote in RT-23660, the problem seems to be in the rendering code. I'll try to contact Java2D team to find out, why they don't have such a problem, but JavaFX does. Anyway, I wouldn't expect them wanting to fix it in the nearest future, unless the fix is absolutely safe, simple and known.
    Thanks,
    Artem

  • Understanding JavaFx, Flex, and Openlaszlo offerings for RIAs

    I'm interested in improving certain aspects of my UI and I recently stumbled upon javafx/flex/openlaszlo (OL). I'd like to understand:
    1. What is needed to develop & deploy javafx. Does it have "gotchas" like Flex, where the sdk is open source, but development and deployment tools are proprietary?
    2. How easy is javafx to pickup?
    3. Specifically, I'd like to use javafx ( or flex/OL) to either augment or replace an editable table I created using js, ajax, html, and css. Is this the type of thing javafx can/should be used for? Are there any drawbacks or pitfalls to using javafx for this rather than straight js, ajax, html, css?
    4. How does javafx compare to flex/OL (as this is a java forum, I do understand that people may not have used flex/OL; but any subjective/objective feedback is helpful)?
    Thanks.

    Does it have "gotchas" like Flex, where the sdk is open source, but development and deployment tools are proprietary?Currently, yes... Only the compiler is open source, the runtime is currently closed. Although it isn't unreasonable to think it might be (at least partially) opened in the future, once it is stabilized.
    Development: can be done with a simple editor and the compiler, and deployment with the command line utility. That's what I use. You can also use NetBeans (open source, decent support of JavaFX) or Eclipse (open source also, support of JFX is a bit lacking, from what I know).
    2. The base is quite easy. You have to forget some habits (from Java in general), you have to know some workarounds, but basically it isn't really hard to learn.
    3. Table support is currently light, it is planned to be more comprehensive. Currently, you can use a number of third party table components. Or if you don't care about mobile phone support, you can still use Swing components.

  • How to pass Objects from Java App to JavaFX Application

    Hello,
    New to the JavaFX. I have a Java Swing Application. I am trying to use the TreeViewer in JavaFX since it seems to be a bit better to use and less confusing.
    Any help is appreciated.
    Thanks
    I have my Java app calling my treeviewer JavaFX as
    -- Java Application --
    public class EPMFrame extends JFrame {
    Customer _custObj
    private void categoryAction(ActionEvent e)   // method called by Toolbar
            ocsCategoryViewer ocsFX;    //javaFX treeviewer
            ocsFX = new ocsCategoryViewer();    // need to pass in the Customer Object to this Not seeing how to do it.
                                                  // tried ocsFX = new ocsCategoryViewer(_custObj) ;    nothing happened even when set this as a string with a value
    public class ocsCategoryViewer extends Application {
    String _customer;
    @Override
        public void start(Stage primaryStage) {
         TreeView <String> ocsTree;
         TreeItem <String> root , subcat;
      TreeItem <String> root = new TreeItem <String> ("/");
            root.setExpanded(true);
             ocsTree = new TreeView <String> (root);
             buildTree();     // this uses the Customer Object.
            StackPane stkp_root = new StackPane();
            stkp_root.getChildren().add(btn);
            stkp_root.getChildren().add(ocsTree);
            Scene scene = new Scene(stkp_root, 300, 250);
            primaryStage.setTitle("Tree Category Viewer");
            primaryStage.setScene(scene);
            primaryStage.show();
        public static void main(String[] args) {
            _customer = args[0];      // temporarily trying to pass in string.
            launch(args);

    JavaFX and Swing integration is documented by Oracle - make sure you understand that before doing further development.
    What are you really trying to do?  The answer to your question depends on the approach you are taking (which I can't really work out from your question).  You will be doing one of:
    1. Run your Swing application and your JavaFX application as different processes and communicate between them.
    This is the case if you have both a Swing application with a main which you launch (e.g. java MySwingApp) and JavaFX application which extends application which you launch independently (e.g. java MyJavaFXApp).
    You will need to do something like open a client/server network socket between the applications and send the data between them.
    2. Run a Swing application with embedded JavaFX components.
    So you just run java MySwingApp.
    You use a JFXPanel, which is "a component to embed JavaFX content into Swing applications."
    3. Run a Java application with embedded Swing components.
    So you just run java MyJavaFXApp.
    You use a SwingNode, which is "used to embed a Swing content into a JavaFX application".
    My recommendation is:
    a. Don't use approach number one and have separate apps written in Swing and Java - that would be pretty complicated and unwarranted for almost all applications.
    b. Don't mix the two toolkits unless you really need to.  An example of a real need is that you have a huge swing app based upon the NetBeans platform and you want to embed a couple of JavaFX graphs in there.  But if your application is only pretty small (e.g., it took less than a month to write), just choose one toolkit or the other and implement your application entirely in that toolkit.  If your entire application is in Swing and you are just using JavaFX because you think its TreeView is easier to program, don't do that; either learn how to use Swing's tree control and use that or rewrite your entire application in JavaFX.  Reasons for my suggestion are listed here: JavaFX Tip 9: Do Not Mix Swing / JavaFX
    c. If you do need to mix the two toolkits, the answer of which approach to use will be obvious.  If you have a huge Swing app and want to embed one or two JavaFX components in it, then use JFXPanel.  If you have a huge JavaFX app and want to embed one or two Swing components in it, use a SwingNode.  Once you do start mixing the two toolkits be very careful about thread processing, which you are almost certain screw up at least during development, no matter how an experienced a developer you are.  Also sharing the data between the Swing and JavaFX components will be trivial as you are now running everything in the same application within the virtual machine and it is all just Java so you can just pass data around as parameters to constructors and method calls, the same way you usually do in a Java program, you can even use static classes and data references to share data but usually a dependency injection framework is better if you are going to do that - personally I'd just stick to simply passing data through method calls.

  • JavaFX in a CDC application

    Hello,
    I am trying to embed a JavaFX scene in swing JComponent as shown below:
    import java.awt.;
    import javax.swing.;
    import org.jfxtras.scene.SceneToJComponent;
    public class Main extends JFrame {
    public static JTextField tf = new JTextField("JavaFX for SWING");
    public Main() {
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("JavaFX in SWING Test");
    Container container = getContentPane();
    container.setLayout(new BorderLayout());
    String sceneClass = "cdcapplication13.MyScene";
    JComponent myScene = SceneToJComponent.loadScene(sceneClass);
    JLabel label = new JLabel(" Below is a JavaFX Animation: ");
    container.add(label, BorderLayout.NORTH);
    container.add(myScene, BorderLayout.CENTER);
    JPanel p = new JPanel();
    p.setLayout(new FlowLayout());
    tf.setColumns(28);
    p.add(tf);
    p.add(new JButton("SWING Button"));
    container.add(p, BorderLayout.SOUTH);
    pack();
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(
    new Runnable() {
    public void run() {
    new Main().setVisible(true);
    In the above cdcapplication13.MyScene is my JavaFX scene class. The above worksfine is a desktop application. However, when trying to do the same on a CDC application with Emulator platform - CDC Java(TM) Platform Micro Edition SDK 3.0, Device - SunVgaAGUIPhone1 and Device Profile - PBP-1.1, I get the following exception when running to app:
    nsicom-run:
    ODT agent stopped.
    java.lang.SecurityException: no manifiest section for signature file entry javax/crypto/KeyGeneratorSpi.class
    at sun.security.util.SignatureFileVerifier.verifySection(SignatureFileVerifier.java:278)
    at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:190)
    at java.util.jar.JarVerifier.processEntry(JarVerifier.java:259)
    at java.util.jar.JarVerifier.update(JarVerifier.java:214)
    at java.util.jar.JarFile.initializeVerifier(JarFile.java:270)
    at java.util.jar.JarFile.getInputStream(JarFile.java:332)
    at sun.misc.Launcher$AppClassLoader.defineClassPrivate(Launcher.java:544)
    at sun.misc.Launcher$AppClassLoader.access$500(Launcher.java:344)
    at sun.misc.Launcher$4.run(Launcher.java:565)
    at java.security.AccessController.doPrivileged(AccessController.java:351)
    at java.security.AccessController.doPrivileged(AccessController.java:320)
    at sun.misc.Launcher$AppClassLoader.doClassFind(Launcher.java:559)
    at sun.misc.Launcher$AppClassLoader.findClass(Launcher.java:607)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:349)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:420)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:338)
    at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:603)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:291)
    at com.sun.cdc.odt.CdcAppManager.runMain(CdcAppManager.java:168)
    at com.sun.cdc.odt.CdcAppManager.access$100(CdcAppManager.java:44)
    at com.sun.cdc.odt.CdcAppManager$1.run(CdcAppManager.java:90)
    at java.lang.Thread.startup(Thread.java:782)
    Can anyone please tell me how to fix this issue?
    Thanks!

    Hi,
    I want to create a CSV file and email it as an
    attachment to a specified email address once the user
    presses Submit in my application. This is developed
    for Sony Ericsson P990i. Can anyone help me with
    this?
    Thanks in advanceI just tried this yesterday, and got to the point where I realized that the Foundation 1.0 JCL, doesn't support what I need from JavaMail 1.4x. Perhaps the alternative, is to read the RFCs, and write a native client, or maybe FTP the file(s)?
    Jeff

  • Performance issues using JavaFX on different notebooks

    Hello,
    unfortunately i feel forced to ask a question about performance issues. As far as i understood, most of the problems with JavaFX 2.0 that are discussed here or somewhere else seem to have there roots in a huge count of nodes and/or some kind of animations. In opposition to this I'm writing a business application for the desktop with JavaFX as a Swing-replacement. There are no permanent animations at all and the scene has all in all 200 nodes(measured it with ScenicView) yet. I use no WebView-Nodes.
    The application runs very well on my development computer with 16 GB of RAM, a Intel Corei7 2600K processor and a mid-class AMD grafics device. Also, there are no performance issues on a Core i3 Notebook. As soon as i start the application on my Thinkpad X220 with Core i7-2620M CPU, 8 GB RAM and Intel HD graphics it get's almost unusable. For example, there is a diagramm(see attached screenshot), which is situated in a scrollpane. As soon as i try to pan it, the panning extremely slow(i'd say 2-4 fps). Another example is that hovering buttons is not very responsive. Moving the mouse over a button causes the hover effect 0.3-0.5 seconds after it entered the button. Fading transitions that i use at some places are not smooth as well.
    I made sure that the app is running using a hardware renderer on each computer. Also, i tried to force a fallback to the software renderer using the "-Dprism.order=j2d" switch but it only performed worse.
    So my first question is: Are there known issues with mobile processors/graphic devices of the mentioned type?

    I just tested it with Java 8 ea build 61 and beside the fact that a small amount of css didn't work anymore, it runs very well with this version of Java(/FX). Damn...i hope that some of this performance fixes will be backported to some Java 7 update.

  • JAVA(Ajax + (SVG or XAML)) is better than JAVA(Swing or SWT)?

    A new startup claims it has invented a process to create reusable Ajax GUI Classes that are better than Java/Swing classes.
    http://cbsdf.com/misc_docs/why-gui-api.htm
    http://cbsdf.com/misc_docs/gui-api-brief.htm
    It has published the innovative process and many examples on the web site and challenging the software community to prove it wrong.
    Any takers?
    It claims the process is very simple any Java developer with some JavaScript experience can validate the process.
    Imagine the implications if they are right, and if it costs less to create a graphics intensive online application than the cost of creating a comparable Java/Swing application?

    Crosspost: http://forum.java.sun.com/thread.jspa?threadID=716694&messageID=4140147

  • JavaFX and the Netbeans platform

    Hi,
    Quick question...does anyone know if there are any plans or ongoing work to port the netbeans platform to JavaFX?
    Nuwanda

    Nuwanda, take a look at these links, perhaps they can help you:
    http://blogs.oracle.com/geertjan/entry/deeper_integration_of_javafx_in
    http://netbeans.dzone.com/javafx-2-in-netbeans-rcp
    http://blogs.oracle.com/geertjan/entry/a_docking_framework_module_system
    http://blogs.oracle.com/geertjan/entry/thanks_javafx_embedded_browser_for
    I think the Netbeans RCP JavaFX strategy would be to enhance Netbeans RCP to provide better support for embedding JavaFX scenes in the platform.
    Converting the platform to be written in JavaFX rather than Swing would not make much sense - such as thing would actually be a completely new platform in it's own right.

  • CDC Application with JavaFX

    Hello,
    I am trying to embed a JavaFX scene in swing JComponent as shown below:
    import java.awt.*;
    import javax.swing.*;
    import org.jfxtras.scene.SceneToJComponent;
    public class Main extends JFrame {
    public static JTextField tf = new JTextField("JavaFX for SWING");
    public Main() {
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("JavaFX in SWING Test");
    Container container = getContentPane();
    container.setLayout(new BorderLayout());
    String sceneClass = "cdcapplication13.MyScene";
    JComponent myScene = SceneToJComponent.loadScene(sceneClass);
    JLabel label = new JLabel(" Below is a JavaFX Animation: ");
    container.add(label, BorderLayout.NORTH);
    container.add(myScene, BorderLayout.CENTER);
    JPanel p = new JPanel();
    p.setLayout(new FlowLayout());
    tf.setColumns(28);
    p.add(tf);
    p.add(new JButton("SWING Button"));
    container.add(p, BorderLayout.SOUTH);
    pack();
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(
    new Runnable() {
    public void run() {
    new Main().setVisible(true);
    In the above cdcapplication13.MyScene is my JavaFX scene class. The above worksfine is a desktop application. However, when trying to do the same on a CDC application with Emulator platform - CDC Java(TM) Platform Micro Edition SDK 3.0, Device - SunVgaAGUIPhone1 and Device Profile - PBP-1.1, I get the following exception when running to app:
    nsicom-run:
    ODT agent stopped.
    java.lang.SecurityException: no manifiest section for signature file entry javax/crypto/KeyGeneratorSpi.class
    at sun.security.util.SignatureFileVerifier.verifySection(SignatureFileVerifier.java:278)
    at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:190)
    at java.util.jar.JarVerifier.processEntry(JarVerifier.java:259)
    at java.util.jar.JarVerifier.update(JarVerifier.java:214)
    at java.util.jar.JarFile.initializeVerifier(JarFile.java:270)
    at java.util.jar.JarFile.getInputStream(JarFile.java:332)
    at sun.misc.Launcher$AppClassLoader.defineClassPrivate(Launcher.java:544)
    at sun.misc.Launcher$AppClassLoader.access$500(Launcher.java:344)
    at sun.misc.Launcher$4.run(Launcher.java:565)
    at java.security.AccessController.doPrivileged(AccessController.java:351)
    at java.security.AccessController.doPrivileged(AccessController.java:320)
    at sun.misc.Launcher$AppClassLoader.doClassFind(Launcher.java:559)
    at sun.misc.Launcher$AppClassLoader.findClass(Launcher.java:607)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:349)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:420)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:338)
    at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:603)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:291)
    at com.sun.cdc.odt.CdcAppManager.runMain(CdcAppManager.java:168)
    at com.sun.cdc.odt.CdcAppManager.access$100(CdcAppManager.java:44)
    at com.sun.cdc.odt.CdcAppManager$1.run(CdcAppManager.java:90)
    at java.lang.Thread.startup(Thread.java:782)
    Can anyone please tell me how to fix this issue?
    Thanks!

    Welcome to the forum. Please don't post in threads that are long dead and don't hijack other threads. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.
    I'm locking this thread now.

  • Is it possible to make a javafx ui application without using layout managers ?

    I want to make an user interface application without using layout managers. In my previous attempt i made an application in java swing. There i used the setBounds() function. Is there any function like setBounds() in javafx ?

    There really isn't any more to it than that.
    Again, I have no idea why you would do things this way (either in JavaFX or in Swing), but:
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.Pane;
    import javafx.stage.Stage;
    public class ManualPositioningExample extends Application {
        @Override
        public void start(Stage primaryStage) {
            final Pane root = new Pane();
            final Button button = new Button("Click me");
            final Label label = new Label("A Label");
            final TextField textField = new TextField();
            root.getChildren().addAll(button, label, textField);
            label.relocate(25, 25);
            textField.relocate(75, 25);
            textField.setPrefSize(100, 20);
            button.relocate(25, 50);
            button.setPrefSize(150, 20);
            Scene scene = new Scene(root, 400, 200);
            primaryStage.setScene(scene);
            primaryStage.show();
        public static void main(String[] args) {
            launch(args);

Maybe you are looking for