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.

Similar Messages

  • How to pass variable from Java to ABAP in BSPs

    Hello experts,
    taking into account the two environments (browser and server) I need to pass information from Java to ABAP.
    After seen this link: Re: View Refresh
    I have tried the next:
    HTMLB:  <input type="hidden" name="myFlag" value="">
    ABAP:   DATA: lv_height TYPE STRING.
    JAVA:   var intXo = readCookie("XEix");
    JAVA:   if ( intXo == 900 )                
    JAVA:   else if (intXo == 725 )            
    ABAP:   lv_height = request->get_form_field( 'myFlag' ).
    ABAP:   IF lv_height EQ 'X'.
    ABAP:     TRAYTAREAS_P = 'TRUE'.
    ABAP:   ELSE.
    ABAP:     TRAYTAREAS_P = 'FALSE'.
    ABAP:   ENDIF. 
    "document.all.myFlag.value" gets the correct value according the condition, but the ABAP code does not recover this value (lv_height is always initial).
    Can you help me with that? I'm not able to see where is the mistake...
    Exist any alternative way to recover in ABAP an JavaScrip value?
    thanks in advance.
    Arnau
    Message was edited by:
            Arnau Mustieles

    Hi Raja
    I think you are appointing to this posted solution:
    HTMLB: <input type="hidden" name="myFlag" value="">
    ABAP: DATA: lv_height TYPE STRING.
    JAVA: var intXo = readCookie("XEix");
    JAVA: if ( intXo == 900 )
    JAVA: else if (intXo == 725 )
    ABAP: lv_height = request->get_form_field( 'myFlag' ).
    ABAP: IF lv_height EQ 'X'.
    ABAP: TRAYTAREAS_P = 'TRUE'.
    ABAP: ELSE.
    ABAP: TRAYTAREAS_P = 'FALSE'.
    ABAP: ENDIF.
    but it doesn't work. Can you detect if there is any evident error there or the process is right?

  • How to pass session from Java to Perl

    Hi,
    I need to pass a session value from Java to Perl, does anyone knows how can I do it?
    Thanks

    If you want to run java code from Perl, and have it return a single value, that's one thing: but having Perl interact with java code - calling methods, returning values - that may not be possible.
    Look into python to see if it may be what you're looking for. It's a scripting language that allows real interaction with java.
    If all you want to do is run java code and have it return some data, that would be trivial, so I assume that's not what you mean. But in case it is heres an idea:
    Set up a network connection between them with your own protocol, seeing as both languages are good at networking.

  • How register COM object from java?

    Hi!
    In my user home directory I have myCOM.dll. My sign applet use this myCOM.dll. But before use this dll I must register it (by use regsvr32).When myCOM.dll will be success register my applet can work. The problem is that I can not get answer from regsvr3 (is myCOM.dll are successed registered or not, or is user has a grants to register COM object and so on.)
    Again, my java applet can work ONLY when myCOM.dll is registered.
    How I can register myCOM.dll from java applet and if registered is not success exit from java applet?

    I must not have been clear. I am not asking how to access a COM object using Java, we already have tools to do that.
    The question is whether there is a way to define a COM interface using Java. I want to code my COM object in Java. Right now we are using PowerBuilder to code COM objects. I would rather use Java.

  • How to pass object from JSF to backing bean

    Hi,
    I have a JSF page using repeater and RichFace Toolbar:
            <h:form id="professional-profile">
                <a4j:repeat value="#{profilesBean.profiles}" var="lang" binding="#{profilesRepeaterBean.repeater}">
                    <rich:togglePanel styleClass="data-input-panel" switchType="client" stateOrder="closed, opened">
                        <f:facet name="closed">
                            <rich:toolBar>
                                <rich:toggleControl switchToState="opened">
                                    <h:graphicImage style="border-width:0" value="../Images/open_btn.gif" />
                                    <rich:toolTip value="#{pp_msg.tooltipOpensPanel}" direction="top-right" showDelay="${config.toolTipDelay}" styleClass="tool-tip"/>
                                </rich:toggleControl>
                                <h:outputText value="#{lang.language}"/>
                            </rich:toolBar>
                        </f:facet>
                        <f:facet name="opened">
                            <h:panelGrid style="width: 100%" columns="1">
                                <rich:toolBar>
                                    <rich:toolBarGroup location="left">
                                        <rich:toggleControl switchToState="closed"
                                                            onclick="if(!ConfirmUnsavedForAction('#{common_msg.unsavedDataWarning}')){return false;}">
                                            <h:graphicImage style="border-width:0" value="../Images/close_btn.gif" />
                                            <rich:toolTip value="#{pp_msg.tooltipClosesPanel}" direction="top-right" showDelay="${config.toolTipDelay}" styleClass="tool-tip"/>
                                        </rich:toggleControl>
                                        <h:outputText value="#{lang.language}"/>
                                        <font class="counterColor">
                                        (#{pp_msg.remainingChars}:</font><h:outputText class="counterColor" id="charsCounter" value="${config.profestionalProfileMaxLength-fn:length(lang.profile)}"/>
                                        <font class="counterColor">)</font>
                                    </rich:toolBarGroup>
                                    <rich:toolBarGroup location="right">
                                        <a4j:commandLink id="submit"
                                                         action="#{cvData.editUsr}"                           <<<<<<<<<<<<<<<<<< THIS LINE
                                                         value="#{common_msg.buttonSave}"
                                                         messagePlace="textarea"
                                                         onclick="CommandOnClick(#{rich:element('textarea')},'#{common_msg.dataSaving}','#{common_msg.dataSaved}');"
                                                         data="#{facesContext.maximumSeverity.ordinal ge 2}"
                                                         oncomplete="CommandOnComplete(#{rich:element('textarea')},data,1500); DataSaved();">
                                        </a4j:commandLink>
                                    </rich:toolBarGroup>
                                </rich:toolBar>
                                <h:inputTextarea
                                    id="textarea"
                                    rows="10"
                                    styleClass="professional-profile-input-area"
                                    binding="#{profilesRepeaterBean.profileInput}"
                                    value="#{lang.profile}"
                                    label="#{pp_msg.header}"
                                </h:inputTextarea>
                            </h:panelGrid>
                        </f:facet>
                    </rich:togglePanel>
                    <br/>
                </a4j:repeat>
            </h:form>Currently all data are stored for all panels at "Save" button click. I want to change it to save only changed panel. For each toolbar an instance of "lang" object is created which i want to send to backing bean where I planned to merge with JPA.
        public void SaveCVProfile(ICvProfileLang profile) {
            cvData.editChangedProfile(profile);
        }All combinations I try gave me just String as parameter value, not an Object reference.
    Any ideas?

    Thanks BalusC,
    I must have messed up my previous tries.
    I used you hint with "f:setPropertyActionListener ".
    <a4j:commandLink id="submit"
                     value="#{common_msg.buttonSave}"   <<<<<< "action"  - REMOVED
                     messagePlace="textarea"
                     onclick="CommandOnClick(#{rich:element('textarea')},'#{common_msg.dataSaving}','#{common_msg.dataSaved}');"
                     data="#{facesContext.maximumSeverity.ordinal ge 2}"
                     oncomplete="CommandOnComplete(#{rich:element('textarea')},data,1500); DataSaved();">
        <rich:toolTip value="#{pp_msg.tooltipButtonSave}" direction="top-left" showDelay="${config.toolTipDelay}" styleClass="tool-tip"/>
        <f:setPropertyActionListener target="#{profilesBean.saveCVProfile}" value="#{lang}" />
    </a4j:commandLink>I removed "action" from commandLink and passed the object to action listener.
    It works as intended now, even without using UIData#getRowData().

  • Pass value from Java to Perl

    Anyone knows how to pass value from Java to Perl program?

    Did you write the perl program? Can you change it? Or are you trying to interface to something that already exists? This will limit your options, of course.
    Anyway the first option is simple. The java program does this:
    System.out.println("This is a line of input.");The perl program does this:
    while(<>)and in that block, $_ is assigned to each line of input.
    Then you can invoke both like this:
    $ java MyJavaProgram | perl MyPerlProgram.pl

  • How to connect to mysql from java app

    hi
    please say the procedure for connecting to mysql database from java app.
    .) what should i give in environmental variables
    .)where can i find the driver class for the mysql
    .) syntax of the url
    eg:- DM.getConnection("jdbc:mysql:..............what comes here..............");

    You can also get connections from a DataSource. Simple example:
                MysqlDataSource msds = new MysqlDataSource();
                msds.setUrl("jdbc:mysql://127.0.0.1:3306/dbdame");
                msds.setUser("user");
                msds.setPassword("pass");
                Connection c = msds.getConnection();Explore your options and be sure to consider connection pooling.

  • How to execute Linux command from Java app.

    Hi all,
    Could anyone show me how to execute Linux command from Java app. For example, I have the need to execute the "ls" command from my Java app (which is running on the Linux machine), how should I write the codes?
    Thanks a lot,

    You can use "built-in" shell commands, you just need to invoke the shell and tell it to run the command. See the -c switch in the man page for your shell. But, "ls" isn't built-in anyays.
    If you use exec, you will want to set the directory with the dir argument to exec, or add it to the command or cmdarray. See the API for the variants of java.lang.Runtime.exec(). (If you're invoking it repeatedly, you can most likely modify a cmdarray more efficiently than having exec() decompose your command).
    You will also definitely want to save the returned Process and read the output from it (possibly stderr too and get an exit status). See API for java.lang.Process. Here's an example
    java.io.BufferedReader br =
    new java.io.BufferedReader(new java.io.InputStreamReader(
    Runtime.getRuntime().exec ("/sbin/ifconfig ppp0").
    getInputStream()));
    while ((s = br.readLine()) != null) {...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to pass data from offline form to webdynpro java

    Hi,
    Please suggest me how to pass data from offline from to webdynpro java node?
    i am using the below code to pass data from offline form(after entering values in the form) to node . i am using form upload ui element to upload offline form and after that i am providng a button to update data.But still i am not able to see data in the node.Any suggestions on this.below code is wriiten on action of the button.
    wdContext.currentContextElement().setPDFSource(null);
           try
                if(null!=wdContext.currentContextElement().getAttributePointer("Resource"))
           IWDResource fileResource = wdContext.currentContextElement().getResource();
         if("PDF".equalsIgnoreCase(fileResource.getResourceType().getFileExtension()))
           byte[] b = new byte[wdContext.currentContextElement().getResource().read(false).available()];
           wdContext.currentContextElement().getResource().read(false).read(b)                     wdContext.currentContextElement().setPDFSource(b);
           WDInteractiveFormHelper.transferPDFDataIntoContext                 (wdContext.currentContextElement().getPDFSource(), wdContext.nodeVn_TestData());                                                               
                     else
                          wdComponentAPI.getMessageManager().reportException("Please enter correct file");
                else
                     wdComponentAPI.getMessageManager().reportException("Error while uploading file"); 
           catch (Exception e) {
                wdComponentAPI.getMessageManager().reportException
                ("Error in uploading the Adobe Form :"+e.getLocalizedMessage(),false);
    Regards,
    Pavani

    If you choose the second alternative you should erase these global variables after the second form is opened
    You can erase the global variable using:
    erase('global_var')
    Greetings,
    Sim

  • How to pass value from jsp to java bean

    I have huge problem . How to pass value from jsp value to java bean.Please replay me soon

    Use the <jsp:setProperty> tag. There are several ways to use it. The one you probably want is:
    <jsp:setProperty name="bean_name"  property="property_name"  value="the_value_you_want_to_set"/>

  • Use HTTP Session to pass Object from Web Dynpro for Java to JSP page

    Is it possible to get a handle on the HTTP Session object from within a Web Dynpro application? I want to place a Java object in there that can be retrieved by a JSP page.
    Thanks in advance.

    Hi Tom Cole,
       You can try this. i am not sure if this will work or not.
    HttpServletRequest request = ((IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletRequest();
    You can also try this.
    IWDRequest mm_request = WDProtocolAdapter.getProtocolAdapter().getRequestObject();
    HttpServletRequest request = (HttpServletRequest)mm_request.getProtocolRequest();
    IWDRequest basically wraps the HttpServletRequest. if you are using NW04s then the getProtocolRequest() may not be available.
    Regards,
    Sanyev

  • Passing parameters from java jdbc to pl/sql

    I’m calling stored procedures from java jdbc… but looking for nicer interfaces in terms of passing data. Has anyone come up with a good way to pass data from java jdbc to pl/sql without passing a million parameters? I’m thinking here of some type of structure like pl/sql rowtype or table index type or something else. Has anyone tried to create typed objects in oracle databases and access them from java?
    Thanks, Patrick Caldwell

    Hi Patrick,
    Yes, I have created an Oracle object type, which I successfully returned to a java class, from a PL/SQL stored function, using JDBC. Environment was J2SE 1.3.1, with Oracle 8.1.7.4 on SUN [sparc] Solaris 7 with Oracle's JDBC (thin) driver. It was a while ago, so I don't remember the details very clearly, but I recall being able to figure it out quite easily using the Oracle documentation and the sample code available at Oracle's Technet Web site.
    Hope this has helped you.
    Good Luck,
    Avi.

  • OBIEE 11g How to pass variable from one prompt to another prompt in dashboard page.

      How to pass variable from one prompt to another prompt in dashboard page.
    I have two prompt in dashboard page as below.
    Reporttype
    prompt: values(Accounting, Operational) Note: values stored as
    presentation variable and they are not coming from table.
    Date prompt values (Account_date, Operation_date)
    Note:values are coming from dim_date table.  
    Now the task is When user select First
    Prompt value  “Accounting” Then in the
    second prompt should display only Accounting_dates , if user select “operational”
    and it should display only operation_dates in second prompt.
    In order to solve this issue I made the
    first prompt “Reporttype” values(Accounting, Operational) as presentation
    values (custom specific values) and default presentation value is accounting.
    In second prompt Date are coming from
    dim_date table and I selected Sql results as shown below.
    SELECT case when '@{Reporttype}'='Accounting'
    then "Dates (Receipts)"."Acct Year"
    else "Dates (Receipts)"."Ops
    Year"  End  FROM "Receipts"
    Issue: Presentation variable value is not
    changing in sql when user select “operation” and second prompt always shows
    acct year in second prompt.
    For testing pupose I kept this presentation
    variable in text object of dashboard and values are changing there, but not in
    second prompt sql.
    Please suggest the solution.

    You will want to use the MoveClipLoader class (using its loadClip() and addListener() methods) rather than loadMovie so that you can wait for the file to load before you try to access anything in it.  You can create an empty movieclip to load the swf into, and in that way the loaded file can be targeted using the empty movieclip instance name.

  • Returning objects from Java stored procedures

    I need to pass an object from Java to a Java SP which updates the object and returns the object back. The Java SP will be calling a PL/SQL procedure which returns some nested tables that I want to stick into the passed object.
    I tried using "IN OUT" for the object in the call spec but got an error that it was not "appropriate for the parameter". So, the next option seems to be to pass it in and then return it from the Java SP. I'm just wondering though what the the best approach for accomplishing this? I've looked through some of the sample code on the OTN but haven't found anything yet that really helps.

    I am trying to use custom object classes. I have setup a type map for the connection and my custom class implements SQLData. Yet, when my client tries to call the Java SP, it gets ORA-00932 complaining of inconsistent data types (expected IN conversion failed).
    I turned on some debug info (i.e. oracle.jdbc.sql=true) but it didn't provide any useful info in regards to why I'm getting this error. Unfortunately, the JDBC Developer's Guide does not provide full examples of the code.

  • How to invoke Matlab from Java

    Hi, I want to pass some data generated from Java class to Matlab, then invoke Matlab from Java to run the computation program (file written in Matlab, myfile.m). I know Matlab can use classes generated from Java, how to drive Matlab from Java?
    I appreciate your help!
    yaya

    According to their documentation, you can't. Having said that, again according to their documentation, there are plans to support this in future releases.
    m

Maybe you are looking for