JNI 4 Swing?

can java native interface colobrate to the javax.swing.* package.

Yes. There's no reason why you should not call JNI methods from a Swing application. Remember however, that ANY long-running method called from the Swing thread (such as in response to a button click), will stall the user interface until it returns. Spin off another thread for long operations.

Similar Messages

  • Swing GUI and JNI

    Hello
    I am facing a problem related to Swing and JNI. Actually I have to call a native function on the action of a button, so I am using Swing to develop GUI. When I use Jframe and Jbuttons and on the action event of JButton when I call the native function of a different class, then the function works fine but suddenly program gets terminated. Program does not get terminated when I click on other buttons but when I click on the button containing native method, after clicking, the whole GUI frame gets removed and the program terminates. While debugging it does not give any error, infact the function works perfectly fine and the only thing that I came to know is that the application gets terminated and it displays "terminated, exit value : - 1073741819"
    Please help me out and reply as soon as possible.

    I imagine it depends on what's in the JNI code. Is this a JNI that you've created? Is it a large program? Can you post the code? Are you sure that you're compiling the C/C++ code with the correct parameters? (you may need to ask some of this in the JNI forum) Is it thread-safe? Are you calling its methods on the EDT?

  • Swing Form = JNI = Delphi DLL = Delphi Form works but small issue

    Hi all
    I'm trying to call a delphi dll from a java form.
    This is the procedure
    swing button action => jni => call procedure in delphi dll => create delphi formThis works for me but the problem is when click the button it create the delphi form by calling the dll but it's stucked for ever(frame not the whole form). Never return to do something else. Means that it's stay remain in clicked postion.
    I do not know whether the problem exist with the swings' single threaded behavior. I have used another thread to call natives. But the problem persist.
    So can any one suggest any answer.
    Wish U all HAPPY NEW YEAR!
    Here is the compact code
    native calls
    public class LoadLib
        public native void createForm();
        public native void forward();
        static
            System.loadLibrary("testjni");
    }calling class
    import javax.swing.*;
    import java.awt.event.ActionEvent;
    import java.awt.Container;
    import java.awt.event.ActionListener;
    public class RUNClient extends JFrame {
         JFrame frame = new JFrame();
         JFrame frame2 = new JFrame();
         LoadLib lib = new LoadLib();
         JButton b1 = new JButton("OK");
         JButton b2 = new JButton("Forwad");
         private RUNClient() {
              frame.setLayout(null);
              frame.add(b1);
              frame.add(b2);
              b1.setBounds(110, 80, 80, 20);
              b2.setBounds(110, 50, 80, 20);
              b1.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        lib.createForm();     // create form in dll
                        // after this call frame is stucked
              b2.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        lib.forward();          // call another native to do some in created form
                        // this cannot be called because frame is stuck
              // other frame operation
         public static void main(String args[]) {
              new RUNClient();
    }delphi code
    library testjni;
    uses
      JNI,Unit1;
      var
      f : TForm1;
    procedure Java_LoadLib_createForm(PEnv: PJNIEnv; Obj: JObject); {$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
    begin
    try
      f := TForm1.Create(nil);
      f.ShowModal;    
       finally
         f.Free;
         f.Release;
       end;
    end;
    procedure Java_LoadLib_forward(PEnv: PJNIEnv; Obj: JObject); {$IFDEF WIN32} stdcall; {$ENDIF} {$IFDEF LINUX} cdecl; {$ENDIF}
    begin
    Form1.Top := Form1.Top - 50;
    end;
    exports
      Java_LoadLib_createForm,
      Java_LoadLib_forward;
    begin
    end.

    Hi deshan,
    To realize the problem you should know principles of Java GUI (SWING or AWT) implementation in JVM:
    1) Java GUI is implemented in a single thread with EventQueue static object, which is created with JVM when Java Application GUI starts.
    2) Any painting or event calls are done on this thread (the same approach was used by Microsoft in .NET GUI).
    3) While your code handles an event EventQueue waits for return from your event method. Some calls to GUI components can stick the whole Java GUI (this is the problem of SUN Java architecture, I did not have this in Microsoft Java). To avoid this problem you should use InvokeLater method that works like PostMessage to the main thread in Windows Application. InvokeLater generate an event that is posted to EventQueue and your code passed to InvokeLater method will be executed asynchronously in GUI Thread.
    4) If you call any Java (SWING or AWT) component from the thread other than EventQueue thread you must synchronize these calls with locks by the object got from getTreeLock() method of the component you call. But you should be accurate with locks because they can cause deadlocks.
    Your code does not return from Click Event where you try to create some GUI component but EventQueue is still waiting for “return” and the main GUI thread is suspended.

  • Using Swing as interface to a dll

    I am trying to use Swing as my cross platform GUI for c++ dll's. Each dll has its own GUI. However, one of my dll's controls what other dlls are loaded. This works fine until I try to load a second instance of the control dll. I get an access violation message when I try to update my gui. If I try to load the two dlls from the c++ everything works fine, but if I load one from the Java GUI I get an null access exception. I'm guessing its caused by one of two problems:
    1) The DLL loading is trashing the executing stack of either the JAVA or the native code.
    2) As the code returns from the constructor call to the newly loaded dll JNI is deleting the interface objects that it is creating on the heap.
    Any ideas would be greatly appreciated.
    Unfortunately I don't get an error log from JAVA.
    VisualStudio gives me:
    Unhandled exception at 0x10014a7d (nativedll.dll) in testjava.exe: 0xC0000005: Access violation reading location 0xfeeefef6.
    The print out reads:
    Creating Java VM
    No. Created VMs 0
    Creating Frame
    Created frame
    Begin master update loop
    Calling Update
    Updated Frame 0
    Creating Java VM
    No. Created VMs 1
    Creating Frame
    Created frame
    Calling Update
    I am using Visual Studio .Net 2003 and jdk 1.4.4, 1.5.0_08 and 1.6.0.
    Main application:
    #include "Windows.h"
    #include "nativelibrary.h"
    #include <stdlib.h>
    #include <string.h>
    #include "jni.h"
    int main(int argc, char* argv[])
           //Load first library
         HMODULE handle = LoadLibrary( "../../nativedll/debug/nativedll.dll");
         nativelibrary* (*funcPtr)();
         funcPtr = (nativelibrary*(*)())GetProcAddress( handle, "createObj");
         nativelibrary* newObj = (*funcPtr)();
            // update each library
         for (int i = 0; i < 10000; i++)
              printf ("Begin master update loop\n");
              void (*funcPtr2)();
              funcPtr2 = (void(*)())GetProcAddress( handle, "update");
              (*funcPtr2)();
              printf ("End master update loop\n");
              Sleep(10);
         // Sleep(100000);
         return 0;
    }Main Library
    #include <iostream>
    #include "jni.h"
    #include "MyFrame.h"
    #include "StaticFunc.h"
    #include <stdlib.h>
    #include <vector>
    #include "Windows.h"
    using namespace std;
    class nativelibrary
    public:
         JavaVM *jvm;
         JNIEnv *env;
         jclass cls;
         jobject myFrame;
         nativelibrary();
         void locupdate();
         static vector<nativelibrary*> objects;
    vector<nativelibrary*> nativelibrary::objects;
    nativelibrary* createObj()
         return new nativelibrary();
    nativelibrary::nativelibrary()
         // JavaVMOption options[0];
         JavaVMInitArgs vm_args;
         memset(&vm_args, 0, sizeof(vm_args));
         vm_args.version = JNI_VERSION_1_4;
         vm_args.nOptions = 0;
         vm_args.ignoreUnrecognized = true;
         vm_args.nOptions = 0;
         // vm_args.options = options;
         JavaVM** jvmBuf = (JavaVM**)malloc(sizeof(JavaVM*));
         jsize buflen = 1;
         jsize nVMs =0;
         // vm_args.options[0].optionString = "-Djava.class.path=../../bin/Debug";
         // Create the Java VM
         printf("Creating Java VM\n");
         jint res = JNI_GetCreatedJavaVMs(jvmBuf, buflen, &nVMs);
         if ( res >= 0)
              printf("No. Created VMs %i\n", nVMs);
              if ( nVMs > 0)
                   jvm = jvmBuf[0];
                   res = jvm->GetEnv((void**)&env,vm_args.version);
              else
                   res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
         else
              res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
         cls = env->FindClass("LMyFrame;");     
         if ( cls == 0 ) printf("Cannot find MyFrame");
         jmethodID mid = env->GetMethodID(cls, "<init>", "()V");
         if ( mid == 0 ) printf("Cannot find constructor");
         printf("Creating Frame\n");
         myFrame = env->NewObject(cls, mid);
         if (env->ExceptionOccurred())
              env->ExceptionDescribe();
         printf("Created frame\n");
         objects.push_back(this);
    void nativelibrary::locupdate()
         printf("Calling Update\n");
         jmethodID updatemid = env->GetMethodID(cls, "update", "()V");
         if ( updatemid == 0 ) printf("Cannot find update");
         env->CallVoidMethod(myFrame, updatemid);
         if (env->ExceptionOccurred())
              env->ExceptionDescribe();
    void update()
         vector<nativelibrary*>::iterator it = nativelibrary::objects.begin();
         while (it != nativelibrary::objects.end())
              nativelibrary* lib = *it;
              lib->locupdate();
              it++;
    JNIEXPORT void JNICALL Java_MyFrame__1createObj
      (JNIEnv *, jclass)
         createObj();
    }Java Class (User interface)
    class MyFrame
         static native void _createObj();
         static int creations = 0;
         int framenum;
         MyFrame()
              System.loadLibrary("../../nativedll/Debug/nativedll");
              framenum = creations++;
         void update()
              System.out.println("Updated Frame " + framenum);
              if ( creations == 1)
                   // load dll as a result of the user clicking on the interface
                   createObj();
         public static void createObj()
              _createObj();
    }

    I am trying to use Swing as my cross platform GUI for c++ dll's. Each dll has its own GUI. However, one of my dll's controls what other dlls are loaded. This works fine until I try to load a second instance of the control dll. I get an access violation message when I try to update my gui. If I try to load the two dlls from the c++ everything works fine, but if I load one from the Java GUI I get an null access exception. I'm guessing its caused by one of two problems:
    1) The DLL loading is trashing the executing stack of either the JAVA or the native code.
    2) As the code returns from the constructor call to the newly loaded dll JNI is deleting the interface objects that it is creating on the heap.
    Any ideas would be greatly appreciated.
    Unfortunately I don't get an error log from JAVA.
    VisualStudio gives me:
    Unhandled exception at 0x10014a7d (nativedll.dll) in testjava.exe: 0xC0000005: Access violation reading location 0xfeeefef6.
    The print out reads:
    Creating Java VM
    No. Created VMs 0
    Creating Frame
    Created frame
    Begin master update loop
    Calling Update
    Updated Frame 0
    Creating Java VM
    No. Created VMs 1
    Creating Frame
    Created frame
    Calling Update
    I am using Visual Studio .Net 2003 and jdk 1.4.4, 1.5.0_08 and 1.6.0.
    Main application:
    #include "Windows.h"
    #include "nativelibrary.h"
    #include <stdlib.h>
    #include <string.h>
    #include "jni.h"
    int main(int argc, char* argv[])
           //Load first library
         HMODULE handle = LoadLibrary( "../../nativedll/debug/nativedll.dll");
         nativelibrary* (*funcPtr)();
         funcPtr = (nativelibrary*(*)())GetProcAddress( handle, "createObj");
         nativelibrary* newObj = (*funcPtr)();
            // update each library
         for (int i = 0; i < 10000; i++)
              printf ("Begin master update loop\n");
              void (*funcPtr2)();
              funcPtr2 = (void(*)())GetProcAddress( handle, "update");
              (*funcPtr2)();
              printf ("End master update loop\n");
              Sleep(10);
         // Sleep(100000);
         return 0;
    }Main Library
    #include <iostream>
    #include "jni.h"
    #include "MyFrame.h"
    #include "StaticFunc.h"
    #include <stdlib.h>
    #include <vector>
    #include "Windows.h"
    using namespace std;
    class nativelibrary
    public:
         JavaVM *jvm;
         JNIEnv *env;
         jclass cls;
         jobject myFrame;
         nativelibrary();
         void locupdate();
         static vector<nativelibrary*> objects;
    vector<nativelibrary*> nativelibrary::objects;
    nativelibrary* createObj()
         return new nativelibrary();
    nativelibrary::nativelibrary()
         // JavaVMOption options[0];
         JavaVMInitArgs vm_args;
         memset(&vm_args, 0, sizeof(vm_args));
         vm_args.version = JNI_VERSION_1_4;
         vm_args.nOptions = 0;
         vm_args.ignoreUnrecognized = true;
         vm_args.nOptions = 0;
         // vm_args.options = options;
         JavaVM** jvmBuf = (JavaVM**)malloc(sizeof(JavaVM*));
         jsize buflen = 1;
         jsize nVMs =0;
         // vm_args.options[0].optionString = "-Djava.class.path=../../bin/Debug";
         // Create the Java VM
         printf("Creating Java VM\n");
         jint res = JNI_GetCreatedJavaVMs(jvmBuf, buflen, &nVMs);
         if ( res >= 0)
              printf("No. Created VMs %i\n", nVMs);
              if ( nVMs > 0)
                   jvm = jvmBuf[0];
                   res = jvm->GetEnv((void**)&env,vm_args.version);
              else
                   res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
         else
              res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
         cls = env->FindClass("LMyFrame;");     
         if ( cls == 0 ) printf("Cannot find MyFrame");
         jmethodID mid = env->GetMethodID(cls, "<init>", "()V");
         if ( mid == 0 ) printf("Cannot find constructor");
         printf("Creating Frame\n");
         myFrame = env->NewObject(cls, mid);
         if (env->ExceptionOccurred())
              env->ExceptionDescribe();
         printf("Created frame\n");
         objects.push_back(this);
    void nativelibrary::locupdate()
         printf("Calling Update\n");
         jmethodID updatemid = env->GetMethodID(cls, "update", "()V");
         if ( updatemid == 0 ) printf("Cannot find update");
         env->CallVoidMethod(myFrame, updatemid);
         if (env->ExceptionOccurred())
              env->ExceptionDescribe();
    void update()
         vector<nativelibrary*>::iterator it = nativelibrary::objects.begin();
         while (it != nativelibrary::objects.end())
              nativelibrary* lib = *it;
              lib->locupdate();
              it++;
    JNIEXPORT void JNICALL Java_MyFrame__1createObj
      (JNIEnv *, jclass)
         createObj();
    }Java Class (User interface)
    class MyFrame
         static native void _createObj();
         static int creations = 0;
         int framenum;
         MyFrame()
              System.loadLibrary("../../nativedll/Debug/nativedll");
              framenum = creations++;
         void update()
              System.out.println("Updated Frame " + framenum);
              if ( creations == 1)
                   // load dll as a result of the user clicking on the interface
                   createObj();
         public static void createObj()
              _createObj();
    }

  • Using console program from java swing

    Can anyone please tell me if the following is possible and how to do it. I want to create a gui for mencoder and so for example i will be wanting toexecute mencoder from the swing app to find out the the auto crop values so i can visually display them. As well when i am actually encoding the files i want to somehow use the progress output from the program and visually display it in swing using a progress bar. I am just quiter sure where to start or even what doing this is called. I know it is possible just now how.
    Cheers
    Damian

    You can use Runtime.exec or ProcessBuilder to run external programs.
    If you do that, I'd suggest trying to use arguments to mencoder that change its console output to be easier to parse. I don't know if such an option exists, but many programs built for the command line provide such options, and mencoder certainly provides a lot of options. Block off a few weeks and you might make your way through a third of the manual.
    Also the mplayer/mencoder suite may provide a C library. I don't recall. If it does, you might be able to use JNI.

  • JNI for C and computer freezes

    I have C code that uses JNI to create a JavaVM and calls my GUI class that creates a Java Swing GUI. This is the code that I use to invoke the JVM:
    JNIEnv *env;
    JavaVM *jvm;
    JavaVMInitArgs vm_args;
    JavaVMOption options[1];
    int nbOptions;
    jint res;
    jclass myJavaClass;
    jmethodID javaGUI, libraryID;
    jmethodID constructorID, guiID;
    vm_args.version = JNI_VERSION_1_2;
    vm_args.nOptions = 1;
    options[0].optionString = "-Djava.class.path=/root/pV3/FinalpV3";
    vm_args.options = options;
    vm_args.ignoreUnrecognized = JNI_FALSE;
    res = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
    if (res < 0) printf("can't create Java VM\n");
    myJavaClass = (*env)->FindClass(env, "Starter");
    if(myJavaClass == 0) printf("can't find Java Class\n");
    guiID = (*env)->GetStaticMethodID(env, myJavaClass, "start", "()V");
    if(guiID == 0) printf("can't find start() ID\n");
    (*env)->CallStaticVoidMethod(env, myJavaClass, guiID);
    However, when I run the C code and (in turn) it creates the Java Swing GUI, if I mess around with the GUI my entire linux machine stalls. Just from experimenting, however, if I don't touch the GUI (i.e. click the buttons and stuff) the program will not freeze my machine. I am not sure the cause of this. I noticed that there is code to destroy the JVM, but do I need to call this?
    Does anyone know what's going on?

    JNI is to call C.
    JNI can call functions written in C++ if the functions are specified as having C linkage.
    Any other language can be called if you can write a C "wrapper" which in turn calls into the other language.

  • Any known issue about running Swing application in WTS?

    *{color:#0000ff}Is there any known issue about running Swing Application in Windows Terminal Server?{color}*
    It is started using JWS from internet (I mean, it checks if there is an avaiable update and updates or just fun).
    _*{color:#800000}+The problem is that just one machine can open the application at the same time+*_
    _*{color}*_
    *{color:#666699}Is there any config in java or jws to run properly several instances of the application (terminal clients)?{color}*
    Edited by: Franzisk on Sep 24, 2007 6:16 PM

    876587 wrote:
    ... and that cause the other threads cannot access the JNI. The same application works fine on other Solaris 10 machines.
    Different environments mean just that. So something could be causing it outside java.
    Additionally if anything at all is different in the execution data, such as even a name having a different size, then it would change the execution path.
    Which would cause a problem in the JNI code to manifest itself on only one box. Probably isn't a pointer bug but all sorts of odd behavior can result from that.

  • Using swing on j#

    i konw there have been programs to use swing on j++, but how about on its upgrade, j#? anyone know if there is a way or there is something in the makes or if there is any way to take the javax package and put it into the j# program file any solutions please let me know

    To be sure, M$ Visual Studio is an excellent IDE (although it has its share of bugs). Perhaps even one of the best out there.But you are confusing the language with the IDE. They ain't the same.
    Java != J++ and Java != J# . The syntax is Java-like, but with additional microsoft extensions, and lacking support for Java facilities such as JNI and RMI.
    IMHO, there's no point in using J#, unless you have a J++ application that you want to port over. If you want to use .net and M$, you may as well use C# - it's a much cleaner break with Java, and consequently contains some niceties that weren't possible with the Java syntax.

  • Solaris java sapgui error JniAgiLibAdaptor. init : Cannot load JNI library

    i have a problem java sapgui.
    Launch the Sapgui and then try to connect to any one of the three choices and it should produce the following error.
    i am running this on a Solaris 10 32bit. This sam java SAPGUI runs fine when i boot into the windows xp pro. Hope this helps.
    gui version;
    SAPGUI for Java 7.10 rev 8 (java),
    no library (lib)
    (Version ID 071000040800)
    Mon Mar 30 10:34:24 MEST 2009
    uw1059, 710_REL, 1054563
    Java VM: Sun Microsystems Inc. Version 1.6.0_14
    OS: SunOS(x86) Version 5.10
    The version of Java being used is:
    java -version
    java version "1.5.0_16"
    Java(TM) Platform, Standard Edition for Business (build 1.5.0_16-b02)
    Java HotSpot(TM) Client VM (build 1.5.0_16-b02, mixed mode, sharing)
    Thank You,
    Ferhan
    JniAgiLibAdaptor.<init>: Cannot load JNI library
    details;
    java.lang.Exception: JniAgiLibAdaptor.<init>: Cannot load JNI library
    at: com.sap.platin.r3.protocol.diag.JniAgiLibAdaptor.<init>(JniAgiLibAdaptor.java:29)
    at: com.sap.platin.r3.protocol.diag.GuiDiagToAutomationParser.configure(GuiDiagToAutomationParser.java:283)
    at: com.sap.platin.base.connection.GuiConnection.open(GuiConnection.java:297)
    at: com.sap.platin.base.application.GuiApplication.createConnection(GuiApplication.java:798)
    at: com.sap.platin.base.logon.GuiLogonFrame.doConnect(GuiLogonFrame.java:838)
    at: com.sap.platin.base.logon.GuiLogonFrame$SymListener.actionPerformed(GuiLogonFrame.java:443)
    at: javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at: javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at: javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at: javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at: javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at: java.awt.Component.processMouseEvent(Unknown Source)
    at: javax.swing.JComponent.processMouseEvent(Unknown Source)
    at: java.awt.Component.processEvent(Unknown Source)
    at: java.awt.Container.processEvent(Unknown Source)
    at: java.awt.Component.dispatchEventImpl(Unknown Source)
    at: java.awt.Container.dispatchEventImpl(Unknown Source)
    at: java.awt.Component.dispatchEvent(Unknown Source)
    at: java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at: java.awt.LightweightDispatcher.proc
    Attempt to load shared library
    /opt/SAPClients/SAPGUI7.10rev8/bin/libJPlatin.so failed.
    The library file exists, so either the program has
    insufficient privileges to access the library or the library
    is not loadable by the shared object loader.
    Please recheck the system requirements for your operating
    system and make sure all required libraries are installed.
    details;
    ava.lang.UnsatisfiedLinkError: /opt/SAPClients/SAPGUI7.10rev8/bin/libJPlatin.so: ld.so.1: java: fatal: /opt/SAPClients/SAPGUI7.10rev8/bin/libJPlatin.so: wrong ELF data format: ELFDATA2MSB (Possible cause: endianness mismatch)
    at: java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at: java.lang.ClassLoader.loadLibrary0(Unknown Source)
    at: java.lang.ClassLoader.loadLibrary(Unknown Source)
    at: java.lang.Runtime.load0(Unknown Source)
    at: java.lang.System.load(Unknown Source)
    at: com.sap.platin.r3.util.GuiJniLoader.loadPlatinLibrary(GuiJniLoader.java:56)
    at: com.sap.platin.r3.protocol.diag.JniAgiLibAdaptor.<init>(JniAgiLibAdaptor.java:27)
    at: com.sap.platin.r3.protocol.diag.GuiDiagToAutomationParser.configure(GuiDiagToAutomationParser.java:283)
    at: com.sap.platin.base.connection.GuiConnection.open(GuiConnection.java:297)
    at: com.sap.platin.base.application.GuiApplication.createConnection(GuiApplication.java:798)
    at: com.sap.platin.base.logon.GuiLogonFrame.doConnect(GuiLogonFrame.java:838)
    at: com.sap.platin.base.logon.GuiLogonFrame$SymListener.actionPerformed(GuiLogonFrame.java:443)
    at: javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at: javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at: javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at: javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at: javax.swing.plaf.basic.BasicB

    Hello Ferhan,
    the output of the AboutBox is indicating that you are trying to run SAP GUI for Java on Solaris 10 with x86 CPU. Unfortunately, the library required to be loaded is complied for SPARC. Please have a look at the system requirements part of the manual coming with the installer of SAP GUI for Java or [note 959236|https://service.sap.com/sap/support/notes/959236].
    Best regards
    Rolf-Martin

  • Java swing tree view interact with indesign javascript

    i have java swing tree view(program).if i execute my program it will all indesign script folder files in tree view. what is my problem is if i click the script
    i want to execute. is it possible to execute indesign javascrpt from java swing UI. could anyone tell me pls.

    Sorry if I did not make this clear:
    This is not an InDesign issue but a Java issue. Search, or ask in a Java forum for best practice to deal with the mentioned platform specific mechanisms:
    - inter process communication (AppleEvent or TLB/OLE )
    - command line / shell script invokation
    - a way to launch an JSX script - the equivalent mechanism to File.execute() in Extendscript.
    For example, if I ask Google for "Java TLB", the second hit takes me to:
    http://dev.eclipse.org/newslists/news.eclipse.tools/msg09883.html
    Eventually you can reuse the DLL and jar - I haven't read that far.
    Google for Java AppleEvent:
    http://developer.apple.com/samplecode/AppleEvent_Send_and_Receive/listing2.html
    Note the 1999 copyright, this is pre-OSX. Also located in a "legacy documents" area. Apple has the bad habit to deprecate/abandon most of their technology every other year, so I would not be surprised if it does not work any more and you'd have to write you own JNI, JDirect or JNIDirect glue ( I don't even know the current buzzword). Ah, further digging unveiled that they even dropped the successor which was named "CocoaJava".
    If Mac specific, maybe post your questions to this list: http://lists.apple.com/mailman/listinfo/java-dev
    Dirk

  • Overriding Interface methods via JNI

    Hello,
    How we can override Interface methods via JNI?
    For example:
    At HelloWorldSwing example:
    http://download.oracle.com/javase/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java
    I've written anonymous Interface as:
    import javax.swing.*;       
    public class HelloWorldSwing1 {
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("HelloWorldSwing");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Add the ubiquitous "Hello World" label.
            JLabel label = new JLabel("Hello World");
            frame.getContentPane().add(label);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        static Runnable runnableObject = new Runnable() {
             public void run() {
                  createAndShowGUI();              
       public static void main(String[] args) {
             //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            SwingUtilities.invokeLater(runnableObject);
    }via JNI functions(http://download.oracle.com/javase/1.4.2/docs/guide/jni/spec/functions.html) we cannot override Runnable Interface's run method? Can we?
    Only:
    RunnableClass's value isn't null with given example at below. FindClass finds the Runnable Interface.
    jclass RunnableClass;
    RunnableClass = (*env)->FindClass(env,"java/lang/Runnable");
      if( RunnableClass == NULL ) {
        printf("can't find class Runnable\n");
        exit (-1);
      }But How can we override Runnable class's run method?
    Thanks in Advance

    The only way you can override a method in Java is by defining a class that does so, either statically or as an anonymous inner class. You can't do either of those things in JNI. Ergo you cannot do what you are asking about.

  • Windows 7 jump list in swing application

    Dear all,
    what is the best way for a hobby programmer to create a windows 7 jump list in a desktop swing application. Does someone know a good example how to do e.g. the jni-calls?
    I know there is a 7Goodies commercial product, but its too expensive for only fun projects.
    Regards Tim

    what is the best way for a hobby programmer to create a windows 7 jump list in a desktop swing application.1. Write or find a command line tool that invokes that functionality.
    2. Use Runtime.exec() or Process Builder to run it.

  • Make my swing app daemon and can show monitor icon in taskbar in window

    hi all
    I have a application in swing.
    when it iconized, i want to it be can not visible, ( this is easy to realize)
    and then I want it can show a task icon at right of task bar in window so that user can make my application visible again.
    I think there is need to write some JNI method to get and control the window instance in window using VC++ or some thing like it.
    But I have no I idea to write it. May be it is some relative to mechanism in JVM.
    So if I use C++ to start my application using "javaw", can I get the window instance that start by the "javaw"
    this request may be not good.
    Thanks in advanced

    These threads have information on how to do this:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=533696
    http://forum.java.sun.com/thread.jsp?forum=31&thread=484691

  • Dlopen and JNI

    Hi all,
    im trying to make a code, that looks like this:
    - javaInterface dynamic library: a library that serves as an interface to some java functions
    - caller: a library that uses the java interface above and call functions
    - executable: calls dlopen to open caller and its functions
    JNI crashes while starting the JVM. The interesting thing is, if instead of using dlopen I compile executable linking with caller, it works. I heard there was an incompatibility with Thread Local Storage and dlopen, and the libc RH EL uses has TLS. Can anyone shed a light here?
    Thanks
    Matheus

    It is quite old, yes. We have to stick to version 1.3, the actual version is
    1.3.1_04 IIRC, because of something coded against specific swing
    peculiarities.
    Of course threads are more efficient, that's their reason to exist.
    However, I haven't been able to find any doc about that, except a single
    sentence mentioning that on Solaris the implementation was not using
    native threads. BTW, I haven't been able to find the source code for
    Linux libjvm either.
    Our C application continuously calls into the JVM to get user's input.
    Should it use mutexes? Catch signals? I cannot work it out without some
    detailed description. Isn't that relevant for programmers? Or is just me
    looking in the wrong places?

  • Getting HWND to Swing component with C++ as main

    I've ran into another issue with the Native interface , it occurs when mixing it with JNI.
    Anyone know why the class load fails on the Native Invocatuon side if I include a JNI call on the Java side??
    Here's the sequence
    1 .Main.cpp -> 2 . MainNativeWindow.cpp (Native Interface) -> 3 . MyWindow.java (create Swing and call Native) -> 4. MyNativeWindow.cpp (get HWND and edit)
    1. So the main app is C++.
    2. The creates a JVM through the native interface
    3. The Java Sides paint is overridden on the C++ side, this gives me a HWND to the Java Canvas.
    4. The C++ side then writes to the Java Canvas.
    My problem is the combination of the Native invocation and the JNI, if I include the JNI call on the Java side then the Native call to access the Java class fails (it works if I remove the JNI function) !!
    Anyone know why the class load fails on the Native Invocatuon side if I include a JNI call on the Java side??
    Is there an easier way to get access to the Java Canvas from the C++ side, besides using the Java Paint function to give me access , I've given snippets of the code below
    1. and 2. C++ main
    #include "MainNativeWindow.h"
    //Native Interface
    #include <stdio.h>
    #include <jni.h>
    JavaVM *jvm; /* Pointer to a Java VM */
    JNIEnv *env; /* Pointer to native method interface */
    int verbose = 1; /* Debugging flag */
    int MainNativeWindow::InitJava()
      JavaVMInitArgs  vm_args;
      jclass cls;
      jmethodID main_methodID, test_methodID = NULL;
      jint res;
      JavaVMOption options[4];
      options[0].optionString = "-Djava.compiler=NONE"; /* disable JIT */
      options[1].optionString = "-Djava.class.path=${JDK_HOME}/lib;C:/jsdk1.4.2/_jvm/lib;."; /* user classes */
      options[2].optionString = "-Djava.library.path=lib"; /* set native library path */
      options[3].optionString = "-verbose:jni"; /* print JNI-related messages */
      /* Setup the environment */
      vm_args.version = JNI_VERSION_1_4;
      vm_args.options = options;
      vm_args.nOptions = 4;
      vm_args.ignoreUnrecognized = 1;
      JNI_GetDefaultJavaVMInitArgs(&vm_args);//REPLACE THIS
       res = JNI_CreateJavaVM(&jvm,(void **) &env, &vm_args );//REPLACE THIS
      cls = env->FindClass("MyWindow");
      if(cls)
        main_methodID = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");//"([Ljava/lang/String;)V" indicates that the Java mehtod takes an array "[" pf Strings and returns void "V"
      if(main_methodID)
         jstring first_str = env->NewStringUTF("The First String");//create string
         jobjectArray args = (jobjectArray)env->NewObjectArray(2,env->FindClass("java/lang/String"), first_str);//new array with 2 elements
                                  env->SetObjectArrayElement(args, 1, first_str);//insert the second string into index 1 of the array
         jstring second_str = env->NewStringUTF("The Second String");//create string
                                  env->SetObjectArrayElement(args, 2, second_str);//insert the second string into index 1 of the array
                             env->CallStaticVoidMethod(cls, main_methodID, args);//pass the array to the Java main method
      jvm->DestroyJavaVM( );
        return 1;
    int main(int argc, char *argv[])
         MainNativeWindow *nativewin = new MainNativeWindow();
          return nativewin->InitJava();   
    }3. JAVA side
    import java.awt.*;
    import javax.swing.*;
    public class MyWindow extends Canvas {
         static {
              // Load the library that contains the paint code.
              System.loadLibrary("MyNativeWindow");
         // native entry point for Painting
         public native void paint(Graphics g);
         public static void main( String[] argv ){
              Frame f = new Frame();
              f.setSize(300,400);
              JWindow w = new JWindow(f);
              w.setBackground(new Color(0,0,0,255));
              w.getContentPane().setBackground(new Color(0,0,0,255));
              w.getContentPane().add(new MyWindow());
              w.setBounds(300,300,300,300);
              w.setVisible(true);
    }4. C++ AWT interface (doesn't get here with the JNI in the Java class)
    //AWT Native Interface
    #include <windows.h>
    #include <assert.h>
    #include "jawt_md.h"
    #include "MyWindow.h"
    void DrawSmiley(HWND hWnd, HDC hdc);
    HRGN hrgn = NULL;
    JNIEXPORT void JNICALL
    Java_MyWindow_paint(JNIEnv* env, jobject canvas, jobject graphics)
         JAWT awt;
         JAWT_DrawingSurface* ds;
         JAWT_DrawingSurfaceInfo* dsi;
         JAWT_Win32DrawingSurfaceInfo* dsi_win;
         jboolean result;
         jint lock;
         // Get the AWT
         awt.version = JAWT_VERSION_1_4;
         result = JAWT_GetAWT(env, &awt);
         assert(result != JNI_FALSE);
         // Get the drawing surface
         ds = awt.GetDrawingSurface(env, canvas);
         if(ds == NULL)
             return;
         // Lock the drawing surface
         lock = ds->Lock(ds);
         assert((lock & JAWT_LOCK_ERROR) == 0);
         // Get the drawing surface info
         dsi = ds->GetDrawingSurfaceInfo(ds);
         // Get the platform-specific drawing info
         dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
         HDC hdc = dsi_win->hdc;
         HWND hWnd = dsi_win->hwnd;
         // !!! DO PAINTING HERE !!! //
         if(hrgn == NULL)
              RECT rcBounds;
              GetWindowRect(hWnd,&rcBounds);
              long xLeft = 0;         // Use with scaling macros
              long yTop = 0;
              long xScale = rcBounds.right-rcBounds.left;
              long yScale = rcBounds.bottom-rcBounds.top;
              hrgn = CreateEllipticRgn(X(10), Y(15), X(90), Y(95));
              SetWindowRgn(GetParent(hWnd),hrgn,TRUE);
              InvalidateRect(hWnd,NULL,TRUE);
         } else {
              DrawSmiley(hWnd,hdc);
         // Free the drawing surface info
         ds->FreeDrawingSurfaceInfo(dsi);
         // Unlock the drawing surface
         ds->Unlock(ds);
         // Free the drawing surface
         awt.FreeDrawingSurface(ds);
    }

    See http://codeproject.com/cpp/OOJNIUse.asp

Maybe you are looking for