PaintChat GUI thread issue using Swing

Hi there, I'm making a paintchat program for fun and have gotten it to work locally but now I would like to add the networking parts in. I have a function like this in a class called Util:
public static NewscastMessage sendMessage(NewscastMessage message, int srcID, IPeerDescriptor dstPeer) {
System.out.println("sending message");
NewscastMessage replyMessage = null;
String errorMessage = null;
try {
Socket socket = new Socket(dstPeer.getAddress(), dstPeer.getPortNumber());
socket.setSoTimeout(5 * 1000); // timeout to 30 seconds
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
out.writeObject(message);
replyMessage = (NewscastMessage)in.readObject();
out.close();
in.close();
socket.close();
return replyMessage;
} catch (ConnectException ex) {
Logger.getLogger(PeerClient.class.getName()).log(Level.SEVERE, ex.getMessage());
errorMessage = ex.getMessage();
} catch (SocketTimeoutException ex) {
Logger.getLogger(PeerClient.class.getName()).log(Level.SEVERE, ex.getMessage());
errorMessage = ex.getMessage();
} catch (IOException ex) {
Logger.getLogger(PeerClient.class.getName()).log(Level.SEVERE, ex.getMessage());
errorMessage = ex.getMessage();
} catch (ClassNotFoundException ex) {
Logger.getLogger(PeerClient.class.getName()).log(Level.SEVERE, ex.getMessage());
errorMessage = ex.getMessage();
} catch (RuntimeException ex) {
Logger.getLogger(PeerClient.class.getName()).log(Level.SEVERE, ex.getMessage());
errorMessage = ex.getMessage();
return new NewscastError(srcID, "While trying to send a message to the Peer with id [ " +
dstPeer.getId() + " ] that has the ip address " + dstPeer.getAddress() + ". \nException on peer " + srcID + ": " + errorMessage);
Essentially when a user types a message into a text field and presses enter, I catch the event and append the text into a text area locally then afterwards I'd like to send this message to a peer via Util.sendMessage. When it gets to this sending part, this error occurs:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
I thought it might be some issues with the event lock and surrounded the call to sendMessage with a synchronize block and didn't work. Any ideas? Thanks in advance.

Sorry forgot to attach the later part:
private void sendTextToDestination(String text){
// send via socket
synchronized (this) {
IPeerDescriptor dst = _peer.getPartialView().getOwnerPeerDescriptor();
NewscastText message = new NewscastText(_peer.getPortNumber(), text);
NewscastMessage replyMessage = null;
replyMessage = Util.sendMessage((NewscastMessage) message, _peer.getPortNumber(), dst);
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
String newline = "\n";
String text = jTextField1.getText();
jTextArea1.append(text + newline);
jTextField1.selectAll(); // after pressing enter, highlight text
//Make sure the new text is visible, even if there
//was a selection in the text area.
jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength());
synchronized(this){
sendTextToDestination(text); -------> this is where the error occurs
}

Similar Messages

  • Threading issue in swing

    From my JDialog(modal ) I am making a RMI call to other machine, this RMI call takes lot of time, so what i
    need is a way to provide user the option of cancelling the task in between. i.e. after invoking
    the call, immediately another dialog should come with the cancel option.
    How can we achieve this? Do we need to use threads for it.
    Thanks in advance

    Search for this site for info on class "SwingWorker" (not part of the SDK). Subclassing SwingWorker allows you to create interruptable background tasks.

  • What is the best way to use Swing GUIs in an MVC design?

    I have a question on how to build an application using swing frames for the UI, but using an MVC architecture. I've checked the rest of the forum, but not found an answer to my question that meets my needs.
    My application at this stage presents a login screen to get the userid and password, or to allow the user to choose a new locale. If an Enter action is performed, the userid and password are checked against the DB. If not accepted, the screen is repainted with a "try-again" message. If the Cancel action is performed, the process stops. If a locale action is performed, the screen is repainted with different langauge labels. Once the login process is passed, a front screen (another swing frame) is presented.
    Implementation: I am using a session object (Session, represents the user logging in) that calls the Login screen (LoginGUI, a Swing JFrame object with various components). Session uses setters in LoginGUI to set the labels, initial field entries etc, before enabling the screen. From this point, the user will do something with the LoginGUI screen - could be closing the window, entering a mix of userid and password, or maybe specifying a locale. Once the user has taken the action, if required, the session object can use getters to retrieve the userid and password values entered in the fields.
    The crux of the problem is 1) how will Session know that an action has been taken on the LoginGUI, and 2) how to tell what action has been taken.
    This could be solved by getting LoginGUI to call back to Session, however, I am trying to buid the application with a good separation of business, logic and presentation (i.e MVC, but not using any specific model). Therefore, I do not want LoginGUI to contain any program flow logic - that should all be contained in Session.
    I am aware of two possible ways to do this:
    1. Make LoginGUI synchronised, so that Session waits for LoginGUI to send a NotifyAll(). LoginGUI could hold a variable indicating what has happened which Session could interrogate.
    2. Implement Window Listener on Session so that it gets informed of the Window Close action. For the other two actions I could use a PropertyChangeListener in Session, that is notified when some variable in LoginGUI is changed. This variable could contain the action performed.
    Has anyone got any comments on the merits of these methods, or perhaps a better method? This technique seems fundamental to any application that interfaces with end-users, so I would like to find the best way.
    Thanks in advance.

    Hi,
    I tried to avoid putting in specific code as my question was more on design, and I wanted to save people having to trawl through specific code. And if I had any school assignments outstanding they would be about 20 years too late :-). I'm not sure computers more sophisticated than an abacus were around then...
    Rather than putting the actual code (which is long and refers to other objects not relevant to the discussion), I have put together two demo classes to illustrate my query. Comments in the code indicate where I have left out non-relevant code.
    Sessiondemo has the main class. When run, it creates an instance of LoginGUIdemo, containing a userid field, password field, a ComboBox (which would normally have a list of available locales), an Enter and a Cancel box.
    When the Locale combo box is clicked, the LoginGUIdemo.userAction button is changed (using an ActionListener) and a property change is fired to Session (which could then perform some work). The same technique is used to detect Enter events (pressing return in password and userid, or clicking on Enter), and to detect Cancel events (clicking on the cancel button). Instead of putting in business code I have just put in System.out.printlns to print the userAction value.
    With this structure, LoginGUIdemo has no business logic, but just alerts Sessiondemo (the class with the business logic).
    Do you know any more elegant way to achieve this function? In my original post, I mentioned that I have also achieved this using thread synchronisation (Sessiondemo waits on LoginGUI to issue a NotifyAll() before it can retrieve the LoginGUI values). I can put together demo code if you would like. Can you post any other demo code to demonstrate a better technique?
    Cheers,
    Alan
    Here's Sessiondemo.class
    import java.io.*;
    import java.awt.event.*;
    import java.util.*;
    import java.beans.*;
    public class Sessiondemo implements PropertyChangeListener {
        private LoginGUIdemo lgui;   // Login screen
        private int localeIndex; // index referring to an array of available Locales
        public Sessiondemo () {
            lgui = new LoginGUIdemo();
            lgui.addPropertyChangeListener(this);
            lgui.show();
        public static void main(String[] args) {
            Sessiondemo sess = new Sessiondemo();
        public void propertyChange(java.beans.PropertyChangeEvent pce) {
            // Get the userAction value from LoginGUI
            String userAction = pce.getNewValue().toString();
            if (userAction == "Cancelled") {
                System.out.println(userAction);
                // close the screen down
                lgui.dispose();
                System.exit(0);
            } else if (userAction == "LocaleChange") {
                System.out.println(userAction);
                // Get the new locale setting from the LoginGUI
                // ...modify LoginGUI labels with new labels from ResourceBundle
    lgui.show();
    } else if (userAction == "Submitted") {
    System.out.println(userAction);
    // ...Get the userid and password values from LoginGUIdemo
                // run some business logic to decide whether to show the login screen again
                // or accept the login and present the application frontscreen
    }And here's LoginGUIdemo.class
    * LoginGUIdemox.java
    * Created on 29 November 2002, 18:59
    * @author  administrator
    import java.beans.*;
    public class LoginGUIdemo extends javax.swing.JFrame {
        private String userAction;
        private PropertyChangeSupport pcs;
        /** Creates new form LoginGUIdemox */
        // Note that in the full code there are setters and getters to allow access to the
        // components in the screen. For clarity they are not included here
        public LoginGUIdemo() {
            pcs = new PropertyChangeSupport(this);
            userAction = "";
            initComponents();
        public void setUserAction(String s) {
            userAction = s;
            pcs.firePropertyChange("userAction",null,userAction);
        public void addPropertyChangeListener(PropertyChangeListener l) {
            pcs.addPropertyChangeListener(l);
        public void removePropertyChangeListener(PropertyChangeListener l) {
            pcs.removePropertyChangeListener(l);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            jTextField1 = new javax.swing.JTextField();
            jTextField2 = new javax.swing.JTextField();
            jComboBox1 = new javax.swing.JComboBox();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            getContentPane().setLayout(new java.awt.FlowLayout());
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            jTextField1.setText("userid");
            jTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    EnterActionPerformed(evt);
            getContentPane().add(jTextField1);
            jTextField2.setText("password");
            jTextField2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    EnterActionPerformed(evt);
            getContentPane().add(jTextField2);
            jComboBox1.setToolTipText("Select Locale");
            jComboBox1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    LocaleActionPerformed(evt);
            getContentPane().add(jComboBox1);
            jButton1.setText("Enter");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    EnterActionPerformed(evt);
            getContentPane().add(jButton1);
            jButton2.setText("Cancel");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    CancelActionPerformed(evt);
            getContentPane().add(jButton2);
            pack();
        private void LocaleActionPerformed(java.awt.event.ActionEvent evt) {
            setUserAction("LocaleChange");
        private void CancelActionPerformed(java.awt.event.ActionEvent evt) {
            setUserAction("Cancelled");
        private void EnterActionPerformed(java.awt.event.ActionEvent evt) {
            setUserAction("Submitted");
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new LoginGUIdemo().show();
        // Variables declaration - do not modify
        private javax.swing.JTextField jTextField2;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton1;
        // End of variables declaration

  • Swing thread issu

    I have a javax.swing.JFrame extended object that after running the code
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new chatUi().setVisible(true);
            });Continues to communicate with a network server over TCP and updates a table with information. By calls to System.out.println I can see that the communication with the server is succesfull but I cant update the gui. The only way i seme able to update the gui after that point is by events that are triggerd by the user and not by functions in my code.
    What am I missing ?
    Is the only way to work with the frame object by creating threads and running them by: SwingUtilities.invokeLater. ??
    Any help would be greatly appriciated // Tomas

    Hi,
    A little bit of more code would be nice to see where your app don't do what it should do.
    In general you should post every code that interacts with the gui into the EventDispatchThread(EDT)
    a common way is to use the EventQueue as you did.
    If one of your methods invokes changes on the gui you should them post on the EDT too.
    If you want to look timebased for a special value or some networkoperations you can use
    a Timer - in your case a javax.swing.Timer and not the java.util.Timer.
    for further informations look at this tutorials :
    http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html
    http://java.sun.com/products/jfc/tsc/articles/timer/
    An other nice way to let run longer threads posting intermediate results on the gui
    is to use a SwingWorker -> javax.swing.SwingWorker
    try those things
    Olek

  • An issue using the COM components supplied with SAP GUI 6.2 or 6.4

    We are having an issue using the COM components supplied with SAP GUI 6.2 or 6.4.  We used to have SAP 4.6c and now we have 5.0.  When we were on 4.6c, we used these COM components to logon and execute RFC calls and we had much success.  Now that we are on 5.0, we can’t seem to instance any SAP functions that have something to do with SAP Workflow.  We have experienced this problem when using VB6 or .NET, but our existing code that always worked is in VB 6.0.
    SAP Components used:
    o     SAP Logon Control
    o     SAP Function Control
    o     Librfc32.dll
    o     Other supporting C DLLs and/or COM object supplied with the SAP GUI installation.
    For example, if we want to call the RFC ARCHIV_CONNECTION_INSERT, this code fails in VB6 when the “Set objworkflow = objFuncCtrl.Add(strFunction)” line of code executes.  Instead of returning an instance of the object ARCHIV_CONNECTION_INSERT function, no object is created.  In 6.2, SAP raises no errors, but the object we are trying to create is still “Nothing”.  If we use 6.4, SAP raises an error “SAP data type not supported” via a message box and then the object is still = Nothing.  Interestingly enough, the 6.2 GUI COM controls don’t display the error dialog.  The message box that is shown comes from the SAP Function COM Object "SAP.Functions" (wdtfuncs.ocx).
    Now, what is interesting is if we use the same code to call a standard function or custom function that doesn’t have anything to do with SAP Workflow, then the code works fine.  Again, all of our code used to work just fine on an SAP 4.6 system.
    Here is the code that fails:
        'SAP Logon control - object for creating connections to an SAP system
        Dim objSAPLogonCtrl As Object
        'SAP connection object
        Dim objConnection As Object
        'Object that will represent the SAP function called
        Dim objSAP As Object
        'SAP function control object - object factory for creating other SAP function objects
        Dim objFuncCtrl As Object
        'Create instance of an SAP logon conrol
        Set objSAPLogonCtrl = CreateObject("SAP.Logoncontrol.1")
        'Create a connection object
        Set objConnection = objSAPLogonCtrl.NewConnection
        'Define connecion parameters
        objConnection.ApplicationServer = "sapvm"
        objConnection.SystemNumber = "00"
        objConnection.Client = "800"
        objConnection.User = "iissap"
        objConnection.Password = "tstadm"
        objConnection.Language = "E"
        objConnection.TraceLevel = 10
        'call the logon method of the connection object
        If objConnection.Logon(0, True) = False Then
            MsgBox Error
            Exit Sub
        End If
        'Create an instance of the SAP Function control object
        Set objFuncCtrl = CreateObject("SAP.Functions")
        'Set the function control connection object
        Set objFuncCtrl.Connection = objConnection
        'Function name to be generated and called
        Dim strFunction As String
        strFunction = <b>"ARCHIV_PROCESS_RFCINPUT"</b>
        'Create an instance of the function defined in strFunction
        Set objworkflow = objFuncCtrl.Add(strFunction)
        If objworkflow Is Nothing Then
            MsgBox "Could not create object " & strFunction
        Else
            MsgBox strFunction & " object created."
        End If
    If anyone has seen anything like this or has any ideas, please help!
    Mike and Hameed
    <b></b>

    Hi,
    documentation on the Scripting API is available at ftp://ftp.sap.com/pub/sapgui/win/640/scripting/docs/
    This API is a replacement of the existing, obsolete COM interfaces.
    Best regards,
    Christian

  • Java swing and threading issue

    i am trying to update swing components from some thread. at my first try, i noticed this was a disaster. upon further research, i found out about the single-threaded model of swing events (i.e. event dispatching thread).
    i did more research and could NOT find a good example on how to update swing components from other threads. many examples were showing too much.
    can someone post a simple example on here? i just want to see how to properly update a swing component from a non-swing class using threading.

    I think its a simple example:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=621226
    Let us know what you think.

  • Packaging concept for GUI and Background, using SwingWorker

    How to set up the following structure, in order to meet the requirements of SwingWorker (doInBackground, publish, process):
    1. There is a class SGui - contained in a package of Swing GUI methods SGui, located in package ...sgui - which will
    - start a background thread, by using SwingWorker, which does some complex logics (the methods from class SSolv, see item 2)
    - it passes initial data to that background process, which have been entered into the GUI
    - displays the intermediate results from the background threat
    2. There is another class SSolv, in package ...ssolv, which contains some complex logics, and should deliver intermediate results to be displayed by the GUI
    From all the information from tutorial etc., I put up a structure like this, for SSolv:
    package ...ssolv;
    class SSolv {
    void senderMethod {
    publish (ComData...)   // should transfer the data to the EDT
    : class ComData {
    //  ... puts up the objects for transferring the data to the GUI, by method publish
    }All the rest of Swing methods goes to package SGui.
    This stub already shows the issue, which comes from structuring the application in two (or even more) packages : compiling package SSolv produces the error publish(V...)
    has protected access in javax.swing.SwingWorker ! I understand that this protected method could only be used in this context, after instancing a subclass of SwingWorker,
    - however I thought it would most senseful to get the "sender" (+publish+), and the "contents" (+ComData+) to the package, where the data will be produced.
    This is evidently in contradiction to the requirement, that publish - as a protected method of SwingWorker - should be defined in the SGui class, as it has to apply the (overriden) methods process (including get), done etc.
    With my application, the SGui class will be compiled later ! So I had to reference a method from SGui that is not known during compiling of SSolv !
    Unfortunately, all the examples shown in the tutorials (as far as I can already know them...) only use one package; so all the classes are compiled from one file, and they will not get this dilemma.
    Please give me some idea, how I will have to restructure / workaround / use advanced methods, to solve this ?
    Edited by: GW.G on 16.07.2010 17:27

    Bad news: I did some homework, but I didn't get it working...
    One reason may be, that your demo doesn't cover my reqs. exactly, regarding implementation of MySwingWorker, because my SSolv - which does all the processing - has to be in the doInBackground() method, and the 'senderMethod' (called dumpExFlags in my SSolv.java) is running integrated from within, because the application SSolv decides, when we have data ready for publishing. See code below...
    Secondly, I really did not get the point with your design, especially with the following segment from MySwingWorker, regarding the use of the private objects sgui and ssolv, and the mechanism of the constructor ?
    import yr2010.m07.d.ssolv.ComData;
    import yr2010.m07.d.ssolv.SSolv;
    public class MySwingWorker extends SwingWorker<Void, ComData> {
       private SGui sgui;
       private SSolv ssolv = new SSolv(this);
       public MySwingWorker(SGui sgui) {
          this.sgui = sgui;
       @Override
       protected Void doInBackground() throws Exception {
          ssolv.senderMethod();
          return null;
       }{code}
    By the way, I analysed the java files with PMD, and didn't find any relevant
    hints why things should not work like that.
    Another tricky detail: the compiler (as well as PMD) reports, that method 'publish' does not 'override', except calling the super method, but your example works !?
    Finally, to my knowledge any type that is overriden, should have his own @Override 'tag'. So did you purposefully omit that in your design ?
    Worst of all, I just ran into the problem that the compiler will not
    recognize all the the variables and methods I imported to the
    DoSolver(SwingWorker subclass). (This may be an issue from my 'bottom
    up' design of my 1000 lines of this first Java example I produced), but:
    I don't see why, in this case, javac ignores all the imports from other
    packages, and reports 'cannot find symbol' on ANYTHING ... ? This puts my debugging efforts on the major problem to halt ...
    {code}
    package s3forum.sgui;
    import javax.swing.;
    import java.util.;
    import s3forum.ssolv.SSolv;
    import s3forum.ssolv.ComData;
    import s3forum.sgui.SGui;
    public class DoSolver extends SwingWorker< Void, ComData > { // SSolv definiert Datenformat
      // DoSolver() - shouldn't be necessary. implicitly defined by instancing with
      // DoSolver dSol = new DoSolver() - should get the overriden methods ready for use
    // ========== Background process, will start when instancing DoSolver
    @Override
    protected Void doInBackground() {
      SSolv slv=new SSolv(vArr); // Instance of solver. vArr=start-values from SGui
    return null;
    //============ Gets data from SSolv coninuously
    @Override
    public void process (java.util.List cDList) {
      if (cDList.size() > 1) { //### Prelim: ignore multiple datasets!
        System.out.println(" ### Multiple values !! ### ");
      ComData cD = cDList.get( cDList.size()-1 );
      dispMLabel (cD.getX, cD.getY, cD.getD);
      if (cD.getIS) {
        dispMText (cD.getX, cD.getY, cD.getD);
    } //Process
    //=========== Postprocessing after SSolver finishes
    @Override
    public void done() {
         // Message
      dispGuiMsg ("Solver ist beendet. FERTIG dr&uuml;cken zum Beenden >");
        // modify button, forcing System.exit()
      fertigB.setActionCommand("fertigWaitEnd");
      fertigB.setEnabled(true);
    //=================== publish, should override method from SwingWorker
    @Override
    public void publish( ComData cd ) {
      super.publish(cd);
    } // Class DoSolver
    {code}
    Could you please further comment on this ? Thank you !
    Edited by: GW.G on 20.07.2010 12:46
    Edited by: GW.G on 20.07.2010 12:48                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Does the lack of Open GL support in Java FX 2 force us to use Swing?

    Hi,
    We are about to start the development of a major User Interface in Java. Naturally, we would prefer to implement this in Java FX 2, rather than Swing. However, we need to render heavy 3D models (generated from several CAD files) with overlay from 3D point clouds with ~400K points. We already have a Swing implementation that supports this, based on the JOGL API. What I have understood, there are no support for JOGL or similar OpenGL wrapper in Java FX 2. Instead, Java FX 2 seems to aim at a high level 3D API. Based on previous attempts to use similar high level API's in the .NET world (e.g. WPF 3D), high level 3D API's are usually not appropriate when working with large and complex 3D models.
    Therefore, I would like to ask for suggestions on what to do here. Do we have to develop our new User Interface in Swing because of this? Or can the announced JavaFX SwingNode be used to wrap such a complex Swing component? If so, how would the performance suffer from the JavaFX wrapping? If the SwingNode doesn't solve the issue and we therefore need to implement the main application in Swing, should we still consider implementing non-3D sub-views with Java FX 2 or should we go for Swing all the way? Our developer group has previous experience from Swing, but none from Java FX. Still, it does not feel right to start the development of a new UI - which we intend to maintain for many years from now - using a deprecated application framework. We are about to decide our way forward here and would really appreciate any thoughts on this topic.
    Thanks,
    Thomas Berglund

    See this StackOverflow question: How to use OpenGL in JavaFX?
    It sounds like the best answer for you is the addition of an OpenGL node to JavaFX.
    An OpenGL node has not yet been added to the JavaFX platform.
    As you have a team of people experienced in 3D development and Java and all of the relevant JavaFX code is open source, I'd encourage you to consider creating an OpenGL node or working with Oracle to create one and (if you are inclined) contributing the development back to the JavaFX code base.  If you are interested in this, contact the openjfx-dev mailing list.
    > Do we have to develop our new User Interface in Swing because of this?
    I don't think so.
    > Or can the announced JavaFX SwingNode be used to wrap such a complex Swing component?
    I don't know, but it doesn't sound quite the right approach to me.
    It seems a dedicated OpenGL rendering node would be a better fit as long as you don't need other Swing functions in your SwingNode.
    > If so, how would the performance suffer from the JavaFX wrapping?
    I think if you had a JavaFX Node which was a Swing Node which handled OpenGL then performance would likely be worse than a JavaFX Node that handled OpenGL directly.
    > If the SwingNode doesn't solve the issue and we therefore need to implement the main application in Swing, should we still consider implementing non-3D sub-views with Java FX 2 or should we go for Swing all the way?
    Either way would work, but I do not recommend mixing the technologies for your application unless you need to.
    There are some considerations with mixing JavaFX and Swing:
    1. Swing widgets look different from JavaFX widgets (and it's not trivial to make them look the same).
    2. You have to learn two toolkits then mentally switch between them when developing (this is just annoying).
    3. You have to be (very) careful of threading issues as each toolkit has it's own primary thread.
    4. There are some bugs in mixing JavaFX and Swing (search JFXPanel in the issue tracker) that simply wouldn't occur if you weren't mixing libraries (most of these bugs have been addressed but some are outstanding).
    5. The Swing functionality isn't going evolve, it's good at what it does, but it is not going to change and get better.
    There is (very experimental) work in merging the JavaFX and Swing application threads, which makes a combined programming model a bit nicer to deal with, but it remains to be seen if that experimental feature becomes a default for both platforms.
    Unless you want to reuse existing extensive Swing libraries (like NetBeans RCP), a pure JavaFX application seems preferred (as long as the OpenGL node can be worked out).
    > Our developer group has previous experience from Swing, but none from Java FX.
    There are similarities, previous knowledge of Swing is a benefit, but there are a lot new things to learn in JavaFX (and a few things to unlearn from Swing likely).
    My 2c . . . best of luck with your project.

  • Using swing in Full screen sxclusive mode

    Hi!
    I have created a game which uses swing components.... I have decieded (because it is much cool, and looks nicer) to convert the game to Full screen mode....
    Mycurrent GUI consists of two JPanel s. One of which I use the paintComponent method to draw the game board to the JPanel. The other JPanel is split into several other parts which contain the details about each player.
    Now, what I want to do is to be able to update the graphics using a BufferStrategy. My question is how would I do this? I tried to create a eperate BufferStrategy for the "Board" JPanel, but I can't as JPanel doesn't support getBufferStrategy(). Then I tried to convert the whole "Board" into Canvas. This I could implemnt but as I rendered the image it was drawn over the second JPanel which is to the right of the "Board"
    I was thinking that maybe I could create a FlipBufferStrategy but it's protected and cannot be instantiated in a JPanel.
    So what I'm basically asking is how do you use swing components in Full Screen Exclusive mode and using active rendering?
    For dukes go to http://forum.java.sun.com/thread.jsp?forum=57&thread=394856&tstart=15&trange=15

    Hi,
    in case you don't already know it, here's Suns very own tutorial on that topic:
    http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html
    JPanel does not support getBufferStrategy() but JFrame (or any other subclass of Window) does. So you could put your JPanel into a JFrame and gain access to the BufferStrategy that way.
    Keep in mind that there is still a serious bug in createBufferStrategy() that can result in a deadlock. Browse the Bug Database for a workaround, I can't find it now, but I know that it is there.
    Last but not least you could post in the Swing Forum, which would be a more suitable place for a Swing question than the Java3D Forum :)
    Regards
    Fleischer

  • Trying to understand "thread-safe" w/ swing components

    The other day there was a big hullabaloo about some code I posted because I was calling JLabel.setText from a thread that wasn't the ui thread. On the other hand, this thread was the only thread making changes to the JLabel. My understanding is that in any kind of multi-threaded system, if you just have 1 writer / changer, then no matter how many readers there are, this is thread-safe. So why what I was doing not thread safe?
    Second question - JLabel.setText() is essentially setting data in the model for JLabel, which then gets picked up and displayed the next time the GUI thread paints it. So if it's not safe to update a JLabel's model, I assume its never safe to update any data that also is being displayed visually. So for instance, if I was showing some database table data in a JTable, I should do the update in the UI thread - probably not. But what is the distinction?
    Third question - what swing components and what operations need to be run on the UI thread to call your program "thread-safe". Validate? setSize()? setLocation()? add? remove? Is there anything that can be called on swing components from a non-ui thread?
    Edited by: tjacobs01 on Nov 2, 2008 8:29 PM

    tjacobs01 wrote:
    My understanding is that in any kind of multi-threaded system, if you just have 1 writer / changer, then no matter how many readers there are, this is thread-safe. So why what I was doing not thread safe?This is not true. As I mentioned in that hullabaloo thread, the Java Memory Model allows threads to cache values of variables they use. This means that values written by one thread are not guaranteed to ever be visible to other threads, unless you use proper synchronization.
    Take the following example:
    import java.util.concurrent.TimeUnit;
    public class ThreadExample {
        static class Foo {
            private String value = "A";
            public String getValue() {
                return value;
            public void setValue(String value) {
                this.value = value;
        public static void main(String[] args) {
            final Foo foo = new Foo();
            Thread writer = new Thread() {
                @Override
                public void run() {
                    try {
                        TimeUnit.SECONDS.sleep(1);
                        foo.setValue("B");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
            Thread reader = new Thread() {
                @Override
                public void run() {
                    try {
                        TimeUnit.MINUTES.sleep(1);
                        System.out.println(foo.getValue());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
            writer.start();
            reader.start();
    }Here two different threads both access the same Foo instance, which is initialized with a value of "A". One thread, the writer, sleeps one second, and then sets foo's value to "B". The other thread, the reader, sleeps one minute (to avoid race conditions) and then prints foo's value to System.out. It may seem obvious that the reader thread will read the value "B", but this is in fact not guaranteed to be true. The reader thread may never see the value that was written by the writer thread, so it may very well read the old value "A".
    (If you run the code you will probably see "B" printed out, but again, this is not guaranteed behavior.)
    A simple way to fix this is to synchronize access to the mutable state that the two threads share. For example, change the class Foo to
        static class Foo {
            private String value = "A";
            public synchronized String getValue() {
                return value;
            public synchronized void setValue(String value) {
                this.value = value;
        }It's for this same reason that you often see the use of a volatile boolean as a control flag for stopping threads, rather than a plain old boolean. The use of volatile guarantees that the thread you want to stop actually sees the new value of the flag once it has been set by another thread.
    Here is an article that touches some of this stuff:
    [http://www.ibm.com/developerworks/java/library/j-jtp02244.html]
    I also highly recommend the book "Java Concurrency in Practice" (one of the authors of which, David Holmes, sometime hangs out on the Concurrency forum here, I believe).
    Edited by: Torgil on Nov 2, 2008 9:01 PM

  • Progress bar on Applet using swing

    Not sure if this is Swing related or applet related, so I'll post it here... :-)
    Long work should be done on a Worker thread an not inside the Swing Dispacher thread .
    So normally I create a Runnable object that calls something like doWork(), and pass the runnable object as a parameter to the Sing utilities invokelater() function.
    My question is inside the worker thread how to update the GUI, in this case the progress bar?
    Can I just call from inside doWork() with no problems the progressbar.setValue(X)?
    Do I need to create another thread and use it too update the UI?
    Is something like this valid ?
    public void doWork() {
    // work work work
    progressbar.setValue(5);
    //more work
    progressbar.setValue(15);
    // and so on
    Thanks for the help!

    Not sure if this is Swing related or applet related,
    so I'll post it here... :-)It's definitely Swing related.
    Long work should be done on a Worker thread an not
    inside the Swing Dispacher thread . This is true.
    So normally I create a Runnable object that calls
    something like doWork(), and pass the runnable object
    as a parameter to the Sing utilities invokelater()
    function.This does not start a worker thread but rather schedules your Runnable object to be run on the EDT.
    My question is inside the worker thread how to update
    the GUI, in this case the progress bar?SwingUtilities or EventQueue have invokeLater and invokeAndWait specifically for this purpose.
    Can I just call from inside doWork() with no problems
    the progressbar.setValue(X)?
    Do I need to create another thread and use it too
    update the UI?No. Here's where you could use invokeLater.
    Is something like this valid ?
    public void doWork() {
    // work work work
    rogressbar.setValue(5);
    //more work
    progressbar.setValue(15);
    // and so onNo.
    >
    Thanks for the help!Like pete has pointed out, this seems to be a job for SwingWorker.

  • Painting issue with swing titlebar

    Hi,
    I had already posted this but no body replied so I am posting it again hoping somebody might reply to this now.
    In my swing application I wanted a custom titlebar, so I created my own RootPaneUI by taking most of the code from MetalRootPaneUI to get what I wanted.
    In order to make my titlebar visible I had to call:
    frame.setUndecorated(true);
    frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
    The major issue I am facing now which sounds very weird to me is with the painting of the window. When I start the application sometimes (not always), I see the frame being stuck to the top left corner of the monitor, when I move the mouse over the toolbar/menubar, the frame starts painting the icons of underlying IDE like eclipse or IntelliJ over my application. It seems like a painting issue which is really a very strange behaviour.
    This issue does not happen with windowslookandfeel and also works fine for MetalLookAndFeel when the JFrame is decorated to show window decorations(windows titlebar) not the look and feel one(custom titlebar).
    I wanted to know if its me who is doing something wrong or is it a swing bug. Is there a way to fix this issue. I searched a number of forums but couldn't find an answer to it.
    Thanks in advance.

    Hello @Andre_Uhres:
    In my application, I am using swing application framework (JSR 296) and I have a splash screen(JFrame) which loads some configuration data and then shows a modal login dialog on top of it. On successful login the login dialog and splash is disposed and the main application frame shows up.
    The job of showing splash screen and logging in the application was being done in the main/initial thread. I apolgoize for not being able to provide a sample runnable code because the issue is seen only with my application and not with any other demo programs and it was not quite possible for me to put that huge code here.
    public static void main(String args[])
    SplashFrame.start();
    //Launch the main application
    Application.launch(ApplicationMain.class); // swing application framework would launch the frame in the invokeLater method.
    class SplashFrame
       public void start()
            // create a splash and show it
           // load the configurations
           // show login dialog
           // on successful login dispose splash and login
    }I eventually moved this code into SwingUtilities.invokeLater() but even this didn't help me. I still see the same issue.
    public static void main(String args[])
    // or use invokeAndWait
    SwingUtilities.invokeLater(new Runnable(){
    SplashFrame.start();
    //Launch the main application
    Application.launch(ApplicationMain.class); // swing application framework would launch the frame in the invokeLater method.
    }I also tried doing this:
      RepaintManager.setCurrentManager(new RepaintManager()); as I read in some forums that sometimes RepaintManager might need to be overwritten to resolve some painting issues.
    FYI: I am using JDK 1.6.0_17
    In spite all these, I still see the same issue. Any help much appreciated.
    Thanks

  • The Single Threaded Nature of Swing

    I am designing a program that uses the basic <i>Model View Controller</i> design pattern. The controller allows you to manipulate the <i>Model</i> and the <i>Views</i> then display a graphical representation of the <i>Model</i>.
    Any way I want to have several different, independent <i>Views</i> of my <i>Model</i>. So I thought; well since the <i>Views</i> are only dependent on the <i>Model</i> I should be able to have the <i>Model</i> raise an event to alert the <i>Views</i> to update their drawing appropriately. Naturally since all the <i>Views</i> are independent I would like them to draw in their own threads, but since Swing is not thread safe it seams that i wont be able to do that.
    As a potential solution I am considered having each <i>Views</i> first create a graphics object that has all the new drawing information, then make a call to repaint through Swings Event Dispatch Thread and and have the component paint method simply BLIT from the pre-rendered graphics object into the graphics Object passed in the paint method. This has the advantage of allowing all the <i>Views</i> to do their drawing code concurrent;y and keep the <i>Controller</i> portion responsive since the even dispatch thread will only have to perform a very simple operation for repaints, however since i have no guarantee as to when the Event Dispatch Thread will actually get around to drawing them I winder if latency will be an issue.
    Non the less I can't help but think that in such a situation it would be safe to multi-thread the drawing. I would like to know if any body else has had to do something similar and what kind of approach they took.
    Flaws in my logic or comments regarding my current solution are also greatly appreciated.

    PCP wrote:
    Any way I want to have several different, independent <i>Views</i> of my <i>Model</i>. So I thought; well since the <i>Views</i> are only dependent on the <i>Model</i> I should be able to have the <i>Model</i> raise an event to alert the <i>Views</i> to update their drawing appropriately. Which is how Swing components work internally, so it all sounds good here.
    Naturally since all the <i>Views</i> are independent I would like them to draw in their own threads, but since Swing is not thread safe it seams that i wont be able to do that.It almost sounds as if you are confusing thread safety with not having the ability to interact with different threads. I'm no Graphics expert, but I think that Swing can handle all this as long as you handle Swing right: Do what you need to do in your separate threads, but just remember to only update Swing components on the EDT.
    As a potential solution I am considered having each <i>Views</i> first create a graphics object that has all the new drawing information, Or perhaps a graphics object derived from a BufferedImage object?
    then make a call to repaint through Swings Event Dispatch Thread and and have the component paint method simply BLIT from the pre-rendered graphics object into the graphics Object passed in the paint method. This has the advantage of allowing all the <i>Views</i> to do their drawing code concurrent;y and keep the <i>Controller</i> portion responsive since the even dispatch thread will only have to perform a very simple operation for repaints, however since i have no guarantee as to when the Event Dispatch Thread will actually get around to drawing them I winder if latency will be an issue.What is the frequency with which you are calling repaints? Have you tried this and found that Swing degrades your program's responsiveness? Again, I'm no graphics expert (where's Darryl, Hiwa, Morgalr when you need them?), but have you considered using active rendering instead of the typical passive rendering?
    Non the less I can't help but think that in such a situation it would be safe to multi-thread the drawing. I would like to know if any body else has had to do something similar and what kind of approach they took. Flaws in my logic or comments regarding my current solution are also greatly appreciated.Whatever happens, please let us know the outcome. Good luck!

  • Modularizing large FX gui apps, esp. using fxml developed by Scene Builder

    StarterApp - One large java source file.
    Trying Out the JavaFX UI Controls (Using the JavaFX UI Controls)
    StageCoach is a simpler app, but with fxml, controller, and main code in separate files.
    Allows manipulation using Scene Builder.
    https://code.google.com/p/jfxtras/source/browse/ProJavaFX/Chapter03/StageCoach?repo=samples&r=322042d9ac293fcd9dd8f63e1664df45a0c4746f
    I was lead to these by the book, Pro JavaFX 8:
    http://www.apress.com/9781430265740
    Rich as it is, the StartApp is one big piece of code, with no modules such as an fxml file.
    By spreading out the code for StarterApp and StageCoach and studying it carefully
    I should be able to build a system as large as StarterApp, but as a three-file combo.
    StarterApp has nothing that deals with concurrency or persistence - those will be my jobs.
    I'm doing this because I'm building a large NLP app.
    It needs a GUI for future users.
    - Bob F

    Take a look at some app examples from the open-jfx repository
      https://wiki.openjdk.java.net/display/OpenJFX/Quick+Start
    For a smallish app, see the ConferenceScheduleApp:
       openjfx/8u-dev/rt: 3d138300d935 /apps/experiments/ConferenceScheduleApp/
    For a (much) larger app, see SceneBuilder:
       http://hg.openjdk.java.net/openjfx/8u-dev/rt/file/3d138300d935/apps/scenebuilder
       Ladstatt: Home made JavaFX SceneBuilder
    For a minimal framework which features FXML and dependency injection, see afterburner.fx:
       http://afterburner.adam-bien.com
    You can skip all of the stuff below if you don't like reading and just want to go code...
    In general for app code, use aggregation over inheritance in most places, though inheritance is useful sometimes.  Don't try to create your own controls by extending the Control class unless you are writing control libraries - that is complex and not well documented as well as largely unnecessary for app code.  Similarly PopupWindow isn't all that great or at least I have never found a need for it in app code - a basic Stage works fine for pretty much every case except perhaps very specialized things like context menus.  Java 8 has built-in dialogs and alerts in 8u40, so for standard dialogs or some reasonably customized dialogs, using those is better than creating your own.  If the standard controls aren't enough, try ControlsFX, it is (mainly) great and high quality.
    Let resizable layout managers do the layout work for you and use constraints in the layout managers and nodes rather than mucking around with fixed sized layouts or layout through binding.
    Don't try to implement a spreadsheet in a JavaFX TableView - just use the built-in controls for what they are good at and either develop a new control for specific functionality not provided by the built-in controls or just skip that feature if it would be too expensive to build it from scratch yourself (and it probably will be expensive - you just have to justify that against your project budget whether that is money or your own time).
    Make use of WebView to bring in web components (e.g. Google Docs or Google Maps).  Don't try and pass a lot of data back and forth between a WebView and your app.
    Don't do any style in code nor in FXML, put it all in a CSS style sheet.
    For medium sized apps - use FXML to design and mark-up your GUI, and use SceneBuilder to create and edit the FXML, don't hand code basic form style UIs - in the long run the FXML based app will be easier to maintain.
    For really small apps and learning tasks, write everything in code against the API so you understand that - use no FXML at all.
    With JavaFX you are writing user interfaces, follow basic user interface design heuristics for which there are some principles to keep in mind.
    Once you have a few FXML pages, passing parameters or sharing data between them is a question that most people run into as well as how to deal with navigation.  That navigation framework I linked is super basic and just meant for pretty simple applications.  A nicer framework which worked in general like a Browser navigation model would be useful - but I haven't seen a generic implementation of such a thing yet - I guess you could create one, but I definitely wouldn't start out trying to do that - instead focus on the basics of your application and get that implemented first.  If you end up needing a reasonably sophisticated navigation framework, eventually you will know it and can evaluate what to do then.
    You can do an awful lot with CSS and styling the built-in controls.  It really is very flexible.  Learn CSS and the JavaFX variant by reading general CSS tutorials (then forget everything HTML specific) and study in depth the JavaFX CSS reference guide and understand its extensions like looked up colors and derivation functions.  When you want to know how some inbuilt thing is styled, go to the modena.css source (which can be hideously obtuse and complicated).  Use ScenicView and SceneBuilder CSS analyzer to understand how CSS is applied to elements.  Don't style borders with boxes - use layered backgrounds, that is how every control modena.css works and how your app should also work.
    Deployment is a difficult topic - so sad and depressing.  For development, just build and run in your IDE.  For production, package the app as a self-contained application. Maybe one day there will be a better deployment model for JavaFX - but that is the best you can get for now.  Completely ignore webstart and web deployment models - any time spent investigating such technologies is completely wasted.
    Do not try to integrate JavaFX and Swing or SWT.  Just write pure JavaFX apps.
    For larger apps you intend to deploy to production, use Maven or Gradle as your build system (you can google the JavaFX plugins for each).  Do not spend any time with the stand-alone JavaFX packager or the JavaFX ant tasks and do not rely on your IDE to do your production builds.
    Get help to targeted questions on StackOverflow.
    Only code to Java 8+ and make use of functional programming techniques.
    Don't write multi-threaded apps unless you know what you are doing.  When you do write multi-threaded apps, use the JavaFX concurrency utilities.  Never modify the active scene graph from another thread, nor touch a property which might trigger an event which might modify the scene graph.  Do use the concurrency utilities if you have network I/O otherwise you will freeze your app while the network I/O occurs and that is a "bad thing".
    The Oracle JavaFX 8 documentation is good - read it and run a lot of the examples (except the ant based deployment ones and the Swing/SWT integration ones).
    Ensemble is great, play with it and study the code to see for the samples (which you can view within Ensemble).
    Binding is programming by side-effect, so be aware that when you change a property, it may trigger some potentially unrelated action through bindings or attached listeners.
    Programming JavaFX in any language other than Java is an experimental thing, so only do that if you like experimenting and are prepared to do so without a lot of support.
    Targeting embedded devices, iOS or Android for a JavaFX app is an experimental thing, so only do that if, yada, yada, yada.
    JavaFX is a mid-level UI system, not a full application stack - it abstracts away the basics like rendering, controls and animation but does not provide comprehensive OS hooks, navigation frameworks, model/view/presenter frameworks, full dependency injection, client/server messaging, data <-> controls serialization and deserialization, etc.  FXML is just a markup system with a binding capability to Java code.  JavaFX and FXML do not constitute a full application framework.  There is no widely-used full application framework for JavaFX.  Sure some people have tried to create one, but none of those solutions have achieved critical mass of usage and features - plus a one-size fits all application framework will never exist anyway - client applications (e.g. a game versus a line-of-business app) differ greatly and deserve completely different architectures.
    There are many things in the Java EE world which can be used in JavaFX (e.g., its dependency injection, its web socket or rest APIs and implementations, its server based systems to allow your app to access cloud based logic and storage, etc) - so feel free to use the bits you need, usually it's as simple as adding additional library dependencies to your maven or gradle project.  A typical medium sized JavaFX application will include multiple third party libraries (mostly non-UI libraries) to get its job done as this will be more convenient than coding everything against the JRE API - though there is an awful lot of out the box functionality you get from the JRE.
    JavaFX is more complicated to use than Delphi and in some respects doesn't supply as much functionality in terms of built-in stuff like data base backed tables (though it supplies a ton more functionality in style).  It is not easier to create a complete business app using JavaFX than it would be to create a similar thing in Microsoft Access in the 90's.  Such is progress.
    JavaFX is portable across desktop environments (OS X, Windows, Mac).  JavaFX apps have their own look and feel which is not like the native OS, but that is probably fine for a lot of apps.  AquaFX does an amazing job of making a JavaFX app looks like OS X apps (kudos to the creators of both AquaFX and the JavaFX built-in styling capabilities).
    Unlike some other portable frameworks like QT, you don't have to write C code, you can write Java code (which to me at least is a win).  Similarly unlike HTML/CSS/JavaScript you don't have to write untyped JavaScript or make use of some obscure code snippet you pulled off the web for your button control.  You don't have to use the web framework of the day which withered yesterday.  Instead you have the (benefit?) of hardly any framework at all for JavaFX.  You don't have to have your app live within a browser sandbox that another developer once described as the ghetto of application sandboxes.
    So, as compared to HTML - I think JavaFX is kinder to the developer, though end users don't really seem to care that much and are fairly accepting of HTML applications even when their functionality is often inferior to many more traditional GUI apps.  HTML is standardized, its full of standards, even the non-standard parts.  Everybody used to implement all the standards differently or make their own standards, however now the standards are so painstakingly, nitpickingly prescriptive that everybody implements pretty much the same thing - except when they don't.  JavaFX has no standard but its public API docs, it has just one implementation.  If you code against the API, your app is probably going to work forever - at least if you bundle the runtime with your app, cause if you don't you might end up like the poor guy in the previous question who can't figure out how to update his app specific CSS rules to get his app to look the same with a newer Java version.  JavaFX is a relatively niche technology and you don't have the legion of developers, tinkerers, industry investments and people just plain getting stuff done in any which way that you have with the whole HTML juggernaut.  The major thing that HTML provides that JavaFX does not is: Sharable, browsable deep links to stuff with search indexed content.  With HTML, Google will index it and you can link to and refer to other docs and other docs can link to yours.  It is the HT in HTML which makes the web so amazing and the F in FXML doesn't match it.  What is the F anyway?
    That's a huge wall'o'text.  Just some random thoughts and opinions.  All opinions are my own.  Your opinions may vary.  That's OK.  I don't think a discussion is needed.  If you would like any clarification or further advice you can ask in new questions.

  • Using ActiveX controls in GUI application, which uses TestStand API

    When using ActiveX controls in TestStand Operator Interface GUI,
    CVI reports User Interface Library error no.-143:
    "ActiveX control Error" on attempt to load panel, which contains ActiveX controls.
    The same code, which takes care of user interface, but not references
    TestStand ActiveX API (i.e. not creates TS Engine), works properly.
    What's wrong?

    Hello again Misha,
    Sorry about my previous answer, I overlooked the fact that you were saying this error was caused by placing ActiveX controls in your Operator Interface (OI) GUI (as my example shows I thought the problem was with GUIs displayed from step code modules).
    Nevertheless, the problem is still being caused by the same issue, and is solved in a similar fashion. The source for the CVI OI initializes the TestStand engine before it loads/displays the UI panels. The calls to initialize the engine seem to be CoInitializing the main GUI thread as multithreaded apartment (MTA) mode whereas you will need it to be single threaded apartment (STA) mode in order for the ActiveX control container to work properly. The TestStand engine is compatible with either modes, but only one can be in place at a given time. If we CoInitialize the OI's main GUI thread as STA this will solve the problem (the subsequent attempts of setting it to MTA will fail, but again this is ok since the engine is compatible with STA).
    In order to perform this functionality you will need to put a call to CoInitializeEx in the main function of the CVI OI source (this will also require that you #include the "windows.h" file at the top of the source also). Here is what the main function in your main.c file for the CVI OI will look like once you have done this:
    int main(int argc, char **argv)
    int retval = -1;
    sArgc = argc;
    sArgv = argv;
    if(InitCVIRTE(0, argv, 0) == 0) /* Initialize CVI libraries */
    goto Done; /* out of memory */
    // Intialize main GUI thread as STA to prevent other attempt to make it
    // MTA, which will not allow ActiveX controls to be used.
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    /* initialize the test engine */
    if(!InitEngine())
    goto Done;
    if(!InitErrorDialogStrings())
    goto Done;
    if(!InStandaloneExecutable() && !DisplayRunningInEnvironmentWarning())
    goto Done; // get out now
    if(!ProcessPreLoginCmdlineArgs())
    goto Done;
    if(!CfgFile_Load())
    goto Done;
    if(!CfgFile_RestoreOptionSettings())
    goto Done;
    if(LoadGUIPanels() < 0)
    goto Done;
    if(!InitFileQuickList())
    goto Done;
    /* set initial gui state */
    if(!InitGUI())
    goto Done;
    RunUserInterface();
    retval = 0; /* normal exist status */
    Done:
    /* cleanup */
    SeqFileList_DeleteAllSequenceFileRecords();
    ExeList_DeleteAllRecords();
    IconList_DeleteIconList();
    SaveAndCleanupFileQuickList();
    CfgFile_SaveOptionSettings();
    CfgFile_WriteAndCleanupForExit();
    AdaptList_DeleteAdapterList();
    DestroyToolMenus();
    CloseEngine();
    FreeErrorDialogStrings();
    return retval;
    Note: Remember to #include "windows.h" at the very top of the main.c file and to include ole32.lib in your project file list in order to link in the definition for CoInitializeEx.
    Jason F.
    Applications Engineer
    National Instruments
    www.ni.com/ask

Maybe you are looking for

  • RE: Help required regarding to upgrade from R/3 4.6c to mySAp ERP 2005

    Hi there I need help as we are planning to upgrade from R/3 4.6C to my SAP ERP 2005, I need the help in the context that . How much it will effect the prevoius functionalities, business processes user exits, reports, transactions and etc which thing

  • ITunes has encountered a problem and needs to close. How to fix it???

    My iPod won't sync to my computer because whenever I hook it up to my computer, it gives me an error that says "iTunes has encountered a problem and needs to close." It then closes. This doesn't happen with my 1G 512 MB iPod Shuffle, just my Black 5G

  • Web application not able to connect to Oracle 10g

    I have been facing an issue with my Web application past 2 days wherein I am not able to connect to oracle database. The error is receive when I compile my project : OCIEnvCreate failed with return code -1 but error message text was not available. I

  • Error 0xE8000001, why can't I synch my iPhone 4s?

    I used to synch my Iphone both wirless and via USB, with no problem at all, but this past week I've been trying to transfer some apps, which sometimes doesn't work wirelessly and I keep getting this error, I plug it in and it starts going crazy like

  • Clean Install On 3rd Party SSD

    My brother has given me his 2010 MacBook Pro with a 256GB SSD running 10.9 and I want to do a clean install of OS X 10.10. Can this be done with a Bootable USB? I have read a few things about this called Trim and was wondering if I need to do somethi