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();
}

Similar Messages

  • Embed Google Maps into Swing Application

    Hi,
    I am trying to build a swing application and i need to embed Google map into it.Is there any way to do this? Which component do i use?
    I guess i am having some difficulty with this because the Swing component needs to support the complex javascript that Gmaps uses.
    Please suggest some solution or API.
    Thanks!

    look on google's site. they have some java component.

  • PDF uploaded into webdynpro application successfully, but unable to open it

    Dear colleagues,
    We have developed a webdynpro appllication in which there is a functionality to add attachments from our local file to the WD applicaiton and save it. Now the  error is that we are able to upload the attachmnets successfully and save it, but when we try to view the file which we upload from the WD application, it gives error message and we are unable to view it. For example, I have PDF form which was uploaded successfully into the WD application and save it. Later when I try to open the PDF form to view it(from the WD application), the adobe reader is opened, but gives error message 'There was an error opening this document. The file is damaged and could not be repaired' and we could not view the contents of the file. Please help me in this regard.
    Note: The PDF file has no errors before uploading into the WD application. Similar kind of error is shown for other file formats also - like *.docx, *.xlsx, *.pdf, *.docm, *.ppt, *.pptx etc.
    Please suggest us how to overcome this error.
    Thanks in advance.
    Regards,
    Vijay

    Hi Vijay,
    are you using business document service to upload the file? There are BAPIs available to save and read the business documents. we used the same concept in our WDA to save and read the attachements to equipment master ie use can see the attachment in IE03 created via WD application and from another WDA, user can read it.
    provide more info about ur application.
    Thanks,
    Chandra

  • How to change the cursor type when a TableView class was added to a Swing application?

    We can resize column width by dragging the column divider in the table header. This is a built-in feature of the TableView class.
    Normally, the cursor will become to east-resize (or west-resize) type with positioning the cursor just to the right of a column header.
    However, I found that the cursor is remaining the default type at the same position if I integrate JavaFX into Swing Application. That is adding the TableView to a Scene, and then adding this Scene to a JFXPanel, finally, adding this JFXPanel to the JFrame.
    The sample codes are listing below:
    public class Run extends JFrame {
        Run() {
            setSize(600, 450);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            initComponents();
        private void initComponents() {
            final JFXPanel fxPanel = new JFXPanel();
            this.getContentPane().add(fxPanel);
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    initFX(fxPanel);
        private void initFX(JFXPanel fxPanel) {
            Scene scene = null;
            try {
                scene = FXMLLoader.load(
                    new File("res/fxml_example.fxml").toURI().toURL()
            } catch (Exception ex) {
                ex.printStackTrace();
            fxPanel.setScene(scene);
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    new Run().setVisible(true);
    fxml_example.fxml:
    <?xml version="1.0" encoding="UTF-8"?>
    <?import javafx.scene.Scene?>
    <?import javafx.scene.control.TableView?>
    <?import javafx.scene.control.TableColumn?>
    <Scene xmlns:fx="http://javafx.com/fxml">
        <TableView fx:id="tableView"
                   editable="true">
            <columns>
                <TableColumn text="COL1">
                </TableColumn>
                <TableColumn text="COL2">
                </TableColumn>
                <TableColumn text="COL3">
                </TableColumn>
                <TableColumn text="COL4">
                </TableColumn>
                <TableColumn text="COL5">
                </TableColumn>
            </columns>
        </TableView>
    </Scene>
    So, are there anyone can advise how to fix these codes; make the cursor can change to east-resize (or west-resize) type when this TableView class was added to a Swing application?

    Thanks for the report. I've just filed a JIRA issue: https://javafx-jira.kenai.com/browse/RT-34009
    //Anton.

  • Swing application w/images

    Hello,
    Java Image I/O provides ways to load and save images into swing applications. Does anyone know of other APIs? We're using Spring/RMI with a Swing client. The images would be stored on the server by index or something. Whats the best approach to write such an application? something that will provide the most flexibility (multiple image formats... viewing, saving, printing etc.) . thanks

    Thanks for the response. Can i incorporate the ability to view TurboCad sketches (.tcw files) using this API?

  • Using JavaFX to rewrite GUI layer for Java Desktop Swing application

    From the faq's on javafx.com I read the following:
    I currently build applications in Java. Can I reuse my Java libraries in JavaFX Script?
    Yes. You can leverage the power of Java by using any Java library within a JavaFX application.
    This way you can preserve your investment in Java and use JavaFX to build engaging visual experiences.
    Can I use JavaFX to develop a user interface for my Java program?
    While it's easy to write your application in JavaFX and call into Java where necessary,
    the inverse - writing a Java application that calls into JavaFX for the user interface - is not yet true.
    We expect this to be addressed in the near future.
    * Perhaps I'm missing something, but I do not see the difference between the two questions, but they give completely different answers?
    * We have a swing application that we might want to use JavaFX to replace the current Swing user interface, however, we also have alot of business logic / communications code written in
    * Java that we aren't going to rewrite.
    Could someone tell me why the two questions have different answers?
    Thanks. Cheers.

    Hi Josh,
    I'm facing serious issue trying to invoke a javafx class from my java code. Could you please suggest a way to do it. Even hacks would be ood enough for now.
    I have created file Clock.fx. When run individually from my IDE (i'm using NetBeans) it works fine. But when i try to invoke it from a java class in project in throws exception.
    public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    JavaFXScriptEngine fxEngine = (JavaFXScriptEngine) manager.getEngineByName("javafx");
    System.out.print("created fxEngine");
    try {
    Object o = fxEngine.eval ("Clock { property: \"Clock\" }");
    fxEngine.invokeMethod (o, "create");
    } catch (Exception ex) {
    ex.printStackTrace();
    I get following exception
    Exception thrown in JavaFX pretty printing: java.io.FileNotFoundException: \tmp\___FX_SCRIPT___.fxdump from StringInputBuffer (The system cannot find the path specified)
    Exception thrown in JavaFX pretty printing: java.io.FileNotFoundException: \tmp\___FX_SCRIPT___.fxdump from StringInputBuffer (The system cannot find the path specified)
    javax.script.ScriptException: compilation failed
    at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.parse(JavaFXScriptEngineImpl.java:255)
    at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.eval(JavaFXScriptEngineImpl.java:145)
    at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.eval(JavaFXScriptEngineImpl.java:136)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
    at newpackage.Main.main(Main.java:29)
    Could you please give a solution to it. I would be obliged.

  • Loading a JPEG into a swing application...

    I need help embedding a JPEG in a swing application(preferrably in it's own container). What should container should I use? Any helpful methods?

    Swing related questions should be posted in the Swing forum.
    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html]How to Use Icons.

  • Entry points for integrating Openoffice writer into Java swing application

    I googled the web and also took a look in below 2 web sites, just seems it is very difficult to get an entry point for me to try my frist application with open office writer integrated with my swing application.
    http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/OpenOffice.org_Developers_Guide
    http://api.openoffice.org/
    What my question is:
    1. Where can I get the completed jar files for using the open office writer api for my java application?
    2. Is there any step by step practical example for using the api? It seems that the above links are quite messy and difficult to find an entry point to get a start, but just contain many segments separated through out the web site.
    Thanks much for any suggestion.

    Information regarding OOo is not on Sun websites, or in these forums. There may be 3rd-party sites that have some info regarding OOo use.

  • Certificate support in Java Swing application

    Hi There,
    I am new to this Certificate thing and running into issues! Would appreciate for all the help and please ignore for any stupid questions.
    Here is my scenario.
    1. I do have a client server application and client is a java swing application which connects to a Server application (Using Jetty 4.2.22 as embedded server)
    2. Initially, it had a self signed certificate but goal is to support third party certificate (i.e import in the server and then show warning to the client during login)
    If somebody has already done this or point me to some example (using Jetty APIs) that would be great help. If not, here is what I am trying to do and some questions.
    1. I tried to get some free SSL certificate from the web and imported into the server's KeyStore.
    If I do a list from the server using Keystore, this is what it looks like
    keytool -list -keystore /tmp/keystore -storepass genview
    Keystore type: JKS
    Keystore provider: SUN
    Your keystore contains 2 entries
    self, Dec 3, 2008, PrivateKeyEntry,
    Certificate fingerprint (MD5): 0D:58:E8:77:89:09:F8:2B:37:64:37:D5:03:AD:C9:0B
    rapid, Jan 6, 2009, trustedCertEntry,
    Certificate fingerprint (MD5): 64:9C:EF:2E:44:FC:C6:8F:52:07:D0:51:73:8F:CB:3
    QUESTION 1 : why the third party certificate's entry as "trustedCertEntry"? Is it always like this? Do I need to have only one certificate at a time? (If so, just remove the self signed and have 3rd party one)
    My Jetty server comes up but when I connect from Client Swing App, the "getServerCertificates()" method only returns one entry i.e self signed one but not the third party one.
    I am using like this
    URL url = new URL("https://127.0.0.1:port");
    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    conn.connect();
    Certificate[] certs = conn.getServerCertificates();
    Is not this API supposed to return all the server's certificate?
    Please guide me or instruct me what to do.
    Thanks,
    CRB

    Crossposted and answered.

  • Is there free java chat, which i can embed in my Swing application

    Hello all,
    I have a Swing application and i want to embed java chat into it.
    Can you recommend me free chat for which i can see and modofy client and server sources.
    Regards,
    Chavdar

    No.

  • How to give Common Background color for all JPanels in My Swing application

    Hi All,
    I am developing a swing application using The Swing Application Framework(SAF)(JSR 296). I this application i have multiple JPanel's embedded in a JTabbedPane. In this way i have three JTabbedPane embedded in a JFrame.
    Now is there any way to set a common background color for the all the JPanel's available in the application??
    I have tried using UIManager.put("Panel.background",new Color.PINK);. But it did not work.
    Also let me know if SAF has some inbuilt method or way to do this.
    Your inputs are valuable.
    Thanks in Advance,
    Nishanth.C

    It is not the fault of NetBeans' GUI builder, JPanels are opaque by default, I mean whether you use Netbeans or not.Thank you!
    I stand corrected (which is short for +"I jumped red-eyed on my feet and rushed to create an SSCCE to demonstrate that JPanels are... mmm... oh well, they are opaque by default... ;-[]"+)
    NetBeans's definitely innocent then, and indeed using it would be an advantage (ctrl-click all JPanels in a form and edit the common opaque property to false) over manually coding
    To handle this it would be better idea to make a subclass of JPanel and override isOpaque() to return false. Then use this 'Trasparent Panel' for all the panels where ever transparency is required.I beg to differ. From a design standpoint, I'd find it terrible (in the pejorative sense of the word) to design a subclass to inconsistently override a getter whereas the standard API already exposes the property (both get and set) for what it's meant: specify whether the panel is opaque.
    Leveraging this subclass would mean changing all lines where a would-be-transparent JPanel is currently instantiated, and instantiate the subclass instead.
    If you're editing all such lines anyway, you might as well change the explicit new JPanel() for a call to a factory method createTransparentJPanel(); this latter could, at the programmer's discretion, implement transparency whichever way makes the programmer's life easier (subclass if he pleases, although that makes me shudder, or simply call thePanel.setOpaque(false) before returning the panel). That way the "transparency" code is centralized in a single easy to maintain location.
    I had to read the code for that latter's UI classes to find out the keys to use (+Panel.background+, Label.foreground, etc.), as I happened to not find this info in an authoritative document - I see that you seem to know thoses keys, may I ask you where you got them from?
    One of best utilities I got from this forum, written by camickr makes getting these keys and their values very easy. You can get it from his blog [(->link)|http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/]
    Definitely. I bit a pair of knucles off when discovered it monthes after cumbersomely traversing the BasicL&F code...
    Still, it is a matter-of-fact approach (and this time I don't mean that to sound pejorative), that works if you can test the result for a given JDK version and L&F, but doesn't guarantee that these keys are there to stand - an observation, but not a specification.
    Thanks TBM for highlighting this blog entry, that's the best keys list device I have found so far, but the questions still holds as to what specifies the keys.
    Edited by: jduprez on Feb 15, 2010 10:07 AM

  • How can I get back into my application aftermath invoking Start up page of index.htm ?

    Gorgeous Hello All,
    If anyone of you can please provide me a solution for the following, will help me in plentious and galore.
    Am using Adobe RoboHelp, Version 10 and IE version being 10.
    A hurdle :-
    I have a application which has been developed in ASP .NET, Version 4.0. Help link has been created in this application wherein here the Start up page of index.htm has been linked to be read from the RoboHelp local project folder\!SSL!\Multiscreen_HTML5\desktop. All are working absolutely fine except when
    I login into the above-said application -> click on the Help page -> the index.htm opens with Contents, Index, Glossary -> Am able to successfully perform any task by respective clickings
    -> But I am not able to get back into my application when I click on the IE provided Back button (Alt+Left) -> Any amount of invoking Back button makes the system getting looped into this Start up page of index.htm only -> When I Close Tab (Ctrl + W) or Close ( X ) -> The window session gets closed and I have to repeat all by relogin once again.
    How can I get back into my application aftermath invoking Start up page of index.htm ?
    (I can always get back into the application easily by erasing those parts in the url which refers to this RoboHelp linkages – but this certainly looks non-polished work)
    Help Please
    Cheese – Vipin Nambiar, Bangalore

    Hey Jeff, I used Internet Explorer 10.0.9200 and Google Chrome 26.0.1410. Alas - it is the same behavior.
    (But Jeff : When I used Microsoft HTML Help as primary layout to generate chm file , My Help when launched from my Application opened in a new browser window and when I closed this Help browser window did not close my application. Looks like need to write few liner code to get this issue settled )
    Thanks Indeed of lots for your concerns Jeff !!!

  • Need Help to update the labels in the GUI syncronously - Swing application

    Hello everyone,
    I need some help regarding a swing application. I am not able to syncronously update the counters and labels that display on my Swing GUI as the application runs in the background. But when the running of application is completed, then the labels on the GUI are getting updated, But I want update the labels and counters on the GUI syncronously as the code executes... below I am giving the format of the code I have written..............
    public class SwingApp extends JFrame{
            // here i have declared the label and component varibles like...
                      private JTextField startTextField;
           private JComboBox maxComboBox;
           private JTextField logTextField;
           private JTextField searchTextField;
           private JLabel imagesDownloaded1;
           private JLabel imagesDownloaded2;
           private JLabel imagesDidnotDownload1;
           private JLabel imagesDidnotDownload2;
                      private JButton startButton;
    //now in the constructer.............
    public Swing(){
    //I used gridbaglayout and wrote the code for the GUI to appear....
    startButton = new JButton("Start Downloading");
        startButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try{
                 actionSearch();   //actionSearch will contain all the code and the function calls of my application...........
            }catch(Exception e1){
                 System.out.println(e1);
        constraints = new GridBagConstraints();
        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.insets = new Insets(5, 5, 5, 5);
        layout.setConstraints(startButton, constraints);
        searchPanel.add(startButton);
    //update is a function which initiates a thread which updates the GUI. this function will be called to pass the required variables in the application
    public void update(final int count_hits, final int counter_image_download1, final int didnot_download1) throws Exception{
         Thread thread = new Thread(new Runnable() {
             public void run() {
                  System.out.println("entered into thread");
                  System.out.println("the variable that has to be set is " + count_hits);
                  server_hits_count.repaint(count_hits);
                  server_hits_count.setText( " "+ Integer.toString(count_hits));
                  imagesDownloaded2.setText(" " + Integer.toString(counter_image_download1));
                  imagesDidnotDownload2.setText(" " + Integer.toString(didnot_download1));
                  repaint();
         //this.update(count_hits);
         thread.start();
    //Now in main............................
    public static void main(String[] args){
    Swing s = new Swing();
    s.setVisible(true);
    }//end of main
    }//end of class SwingAbove I have given the skeleton code of my application........ Please tell me how to update the GUI syncronously...
    Please its a bit urgent...............
    Thank you very much in advance
    chaitanya

    First off, note that this question should have been posted in the Swing section.
    GUI events run in a separate thread (the AWT / Event Dispatch Thread) than your program.
    You should be invoking AWT/Swing events via SwingUtilities.invokeLater().
    If for whatever reason you want to have the program thread wait for the event to process
    you can use invokeAndWait().
    http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html

  • Problem with JavaFX 8 Self-contained Application !

    Hello everybody,
    I generate a JavaFX 8 Self-Contained Application for Windows (.msi).
    Eclipse 4.3.1 (Kepler)
    JDK 8 B116 (EA - i don't use the lasts beta versions (B117 and B118) because there is a bug during installation for Windows XP)
    Scene builder 2.0 (EA)
    When i install this application (exec .msi) on my PC (Windows XP SP3 - JDK 7 and 8 installed), no problem.
    So i install this application on 2 others PC (PC without JDK 8 installed).
    The first PC on Windows XP SP3 (JDK 5 and 6 installed) : display problem - the font is very big as if I had made a zoom on the contents of the window !
    The second PC on Windows 7 PRO (JDK 7 installed) - when in launch the application by the system menu, i have two strange problems
    1/ when i move my mouse on the content of the window, this content becomes black !
    2/ it's necessary to resize the window (full screen) and to come back to the original size to obtain a correct display !
    I don't know where is the problem(s) ?
    is it linked to JDK 8 (BETA version) embedded ?
    If you have a idea do not hesitate !
    Thanks you in advance
    IBACK

    I only use external FW HDDs for my video work; my Capture Scratch files are on external drives and I export finished movies to external drives. My project files are on my system drive, this is the best way to work, I have never had any problems I could associate with this configuration
    I am assuming you've gone thru your project, your timeline and everything is kosher. Is everything fully rendered? Have you mixed down your audio? Have you tried exporting just the last 30 seconds of one of the projects to see if you can replicate the problem?

  • Where i Put my swing application jar file in jboss

    Hi experts...
    I develope swing application and convert it into jar file....I know jnlp deployment using tomcat..In tomcat i
    put my appcation.jar in webapps/root folder...This is not similar in jboss..I dont know where i put my applcation.jar in jboss.If any body know the idea please let me know..

    Hi
    You have to put your jar file in
    server/default/deploy
    Regards
    M Fazal Ur Rehman

Maybe you are looking for

  • Connect SAP R/3 to Portals

    Hi, Need help creating a connection to SAP R/3. Firstly, Can we use EP to connect to R/3 4.6C version ? I have the following paramters when I create a SAP system in 'System Landscape' in EP. I dont see an entry for client, host, user, app server etc.

  • PC not detecting WRT54GS v7

    Having a bit of trouble here. Just bought a WRT54GS v7 from Wal-Mart and it won't get past the 'Detecting Router' step in the EasyLink setup. I know for a fact that I've got all my wires connected properly, and in the right order, but my PC just isn'

  • Trying to install Windows

    I'm trying to partiton my hard drive using boot camp but it says it can't install because of a network issue.  Any ideas?

  • Default Standard Text Key or Standard Text to first Operation of Order

    I would like to have a standard text key or standard text defaulted for the first operation of an order created via IW31 of certain order type. For example we have an order type called CORR for corrective orders.  When ever there is a break fix, the

  • Got this error message

    Hi... I'm facing this error message "Uncaught exception java/lang/NullPointerException." whenever i run the emulator. The code does not seems to have any error message but it happens when dat particular method is invoking another method from another