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?

Similar Messages

  • Spreadsheets and SWING GUI's

    I have to embed a spreadsheet facility in a SWING GUI, what is the best and easiest way to do this ??

    I am not quite sure what your problem is.
    The way I see it, your question is one of the following:
    1. How do I (generally) make a user interface on top of my dos-based program?
    2. How do I make user interfaces in swing?
    If your question is the first, I'm afraid I can't tell you either. Would seem pretty obvious to me, make a simple dialog based app, using menu's or actions to trigger tha actions that were formerly triggered by numbers, etc...
    In the other case, I recommend the java swing tutorial at http://java.sun.com/docs/books/tutorial/uiswing/
    Greetings,
    Gert

  • Problem with java swing button and loop

    Problem with java swing button and loop
    I�m using VAJ 4.0. and I�m doing normal GUI application. I have next problem.
    I have in the same class two jswing buttons named start (ivjGStart) and stop (ivjGStop) and private static int field named Status where initial value is 0. This buttons should work something like this:
    When I click on start button it must do next:
    Start button must set disenabled and Stop button must set enabled and selected. Field status is set to 1, because this is a condition in next procedure in some loop. And then procedure named IzvajajNeprekinjeno() is invoked.
    And when I click on stop button it must do next:
    Start button must set enabled and selected and Stop button must set disenabled.
    Field status is set to 0.
    This works everything fine without loop �do .. while� inside the procedure IzvajajNeprekinjeno(). But when used this loop the start button all the time stay (like) pressed. And this means that a can�t stop my loop.
    There is java code, so you can get better picture:
    /** start button */
    public void gStart_ActionEvents() {
    try {
    ivjGStart.setEnabled(false);
    ivjGStop.setEnabled(true);
    ivjGStop.setSelected(true);
    getJTextPane1().setText("Program is running ...");
    Status = 1;
    } catch (Exception e) {}
    /** stop button */
    public void gStop_ActionEvents() {
    try {
    ivjGStart.setEnabled(true);
    ivjGStart.setSelected(true);
    ivjGStop.setEnabled(false);
    getJTextPane1().setText("Program is NOT running ...");
    Status = 0;
    } catch (Exception e) {
    /** procedure IzvajajNeprekinjeno() */
    public void IzvajajNeprekinjeno() {  //RunLoop
    try {
    int zamik = 2000; //delay
    do {
    Thread.sleep(zamik);
    PreberiDat(); //procedure
    } while (Status == 1);
    } catch (Exception e) {
    So, I'm asking what I have to do, that start button will not all the time stay pressed? Or some other aspect of solving this problem.
    Any help will be appreciated.
    Best regards,
    Tomi

    This is a multi thread problem. When you start the gui, it is running in one thread. Lets call that GUI_Thread so we know what we are talking about.
    Since java is task-based this will happen if you do like this:
    1. Button "Start" is pressed. Thread running: GUI_Thread
    2. Event gStart_ActionEvents() called. Thread running: GUI_Thread
    3. Method IzvajajNeprekinjeno() called. Thread running: GUI_Thread
    4. Sleep in method IzvajajNeprekinjeno() on thread GUI_Thread
    5. Call PreberiDat(). Thread running: GUI_Thread
    6. Check status. If == 1, go tho 4. Thread running: GUI_Thread.
    Since the method IzvajajNeprekinjeno() (what does that mean?) and the GUI is running in the same thread and the event that the Start button has thrown isn't done yet, the program will go on in the IzvajajNeprekinjeno() method forever and never let you press the Stop-button.
    What you have to do is do put either the GUI in a thread of its own or start a new thread that will do the task of the IzvajajNeprekinjeno() method.
    http://java.sun.com/docs/books/tutorial/uiswing/index.html
    This tutorial explains how to build a multi threaded gui.
    /Lime

  • Loading large files in Java Swing GUI

    Hello Everyone!
    I am trying to load large files(more then 70 MB of xml text) in a Java Swing GUI. I tried several approaches,
    1)Byte based loading whith a loop similar to
    pane.setText("");
                 InputStream file_reader = new BufferedInputStream(new FileInputStream
                           (file));
                 int BUFFER_SIZE = 4096;
                 byte[] buffer = new byte[BUFFER_SIZE];
                 int bytesRead;
                 String line;
                 while ((bytesRead = file_reader.read(buffer, 0, BUFFER_SIZE)) != -1)
                      line = new String(buffer, 0, bytesRead);
                      pane.append(line);
                 }But this is gives me unacceptable response times for large files and runs out of Java Heap memory.
    2) I read in several places that I could load only small chunks of the file at a time and when the user scrolls upwards or downwards the next/previous chunk is loaded , to achieve this I am guessing extensive manipulation for the ScrollBar in the JScrollPane will be needed or adding an external JScrollBar perhaps? Can anyone provide sample code for that approach? (Putting in mind that I am writting code for an editor so I will be needing to interact via clicks and mouse wheel roatation and keyboard buttons and so on...)
    If anyone can help me, post sample code or point me to useful links that deal with this issue or with writting code for editors in general I would be very grateful.
    Thank you in advance.

    Hi,
    I'm replying to your question from another thread.
    To handle large files I used the new IO libary. I'm trying to remember off the top of my head but the classes involved were the RandomAccessFile, FileChannel and MappedByteBuffer. The MappedByteBuffer was the best way for me to read and write to the file.
    When opening the file I had to scan through the contents of the file using a swing worker thread and progress monitor. Whilst doing this I indexed the file into managable chunks. I also created a cache to further optimise file access.
    In all it worked really well and I was suprised by the performance of the new IO libraries. I remember loading 1GB files and whilst having to wait a few seconds to perform the indexing you wouldn't know that the data for the JList was being retrieved from a file whilst the application was running.
    Good Luck,
    Martin.

  • Running a Java application from a Swing GUI

    Hi,
    I was wondering if there is a simple way to run a Java application from a GUI built with Swing. I would presume there would be, because the Swing GUI is a Java application itself, technically.
    So, I want a user to click a button on my GUI, and then have another Java application, which is in the same package with the same classpaths and stuff, run.
    Is there a simple way to do this? Do any tutorials exist on this? If someone could give me any advice, or even a simple "yes this is possible, and it is simple" or "this is possible, but difficult" or "no this is not possible" answer, I would appreciate it. If anyone needs more information, I'll be happy to provide it.
    Thanks,
    Dan

    I don't know if it is possible to run the main method from another Java app by simply calling it...
    But you could just copy and paste the stuff from your main method into a new static method called something like runDBQuery and have all the execution run from there.
    How does that sound? Is it possible?
    What I'm suggeting is:
    Original
    public class DBQuery{
    public static void methodA(){
    public static void doQuery(){
    methodA();
    public static void main(String[] args){
    // Your method calls
    //Your initializing
    doQuery();
    }Revised:
    public class DBQuery{
    public static void methodA(){
    public static void doQuery(){
    methodA();
    public static void doMyQuery(){
    // Your method calls
    //Your initializing
    doQuery();
    // No main needed!!
    //public static void main(String[] args){
    // Your method calls
    //doQuery();
    //}

  • (Youtube-) Video in a Swing GUI

    Hey everyone,
    I'm currently trying to play a video in my Swing GUI with JMF but I really can't get it to work.
    With the help of google I got this far:
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.media.CannotRealizeException;
    import javax.media.Manager;
    import javax.media.NoPlayerException;
    import javax.media.Player;
    import javax.swing.JFrame;
    public class MediaPanel extends JFrame {
        public MediaPanel() {
            setLayout(new BorderLayout()); // use a BorderLayout
            // Use lightweight components for Swing compatibility
            Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
            URL mediaURL = null;
            try {
                mediaURL = new URL("http://www.youtube.com/watch?v=Q7_Z_mQUBa8");
            } catch (MalformedURLException ex) {
                System.err.println(ex);
            try {
                // create a player to play the media specified in the URL
                Player mediaPlayer = Manager.createRealizedPlayer(mediaURL);
                // get the components for the video and the playback controls
                Component video = mediaPlayer.getVisualComponent();
                Component controls = mediaPlayer.getControlPanelComponent();
                if (video != null) {
                    add(video, BorderLayout.CENTER); // add video component
                if (controls != null) {
                    add(controls, BorderLayout.SOUTH); // add controls
                mediaPlayer.start(); // start playing the media clip
            } // end try
            catch (NoPlayerException noPlayerException) {
                System.err.println("No media player found");
            } // end catch
            catch (CannotRealizeException cannotRealizeException) {
                System.err.println("Could not realize media player");
            } // end catch
            catch (IOException iOException) {
                System.err.println("Error reading from the source");
            } // end catch
        } // end MediaPanel constructor
    }But all I get is errors:
    Warning: The URL may not exist. Please check URL
    No media player found
    Can you please please help me get this working? I would really appreciate a little walkthrough
    Best regards,
    Patrick
    Edited by: 954807 on Aug 24, 2012 6:52 AM

    Just use \ tags. People don't like to go to external sites.
    I really advise you to consider using JavaFX 2 here. Swing is old and not really supported anymore, JMF is also old and absolutely not supported anymore.                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • In this case, can I modify swing GUI out of swing thread?

    I know the Swing single thread rule and design (Swing is not thread safe).
    For time-consuming task, we are using other thread to do the task and
    we use SwingUtilities.invokeAndWait() or SwingUtilities.invokeLater (or SwingWorker) to update Swing GUI.
    My problem is, my time-consuming task is related to Swing GUI stuff
    (like set expanded state of a huge tree, walk through entire tree... etc), not the classic DB task.
    So my time-consuming Swing task must executed on Swing thread, but it will block the GUI responsivity.
    I solve this problem by show up a modal waiting dialog to ask user to wait and
    also allow user to cancel the task.
    Then I create an other thread (no event-dispatch thread) to do my Swing time-consuming tasks.
    Since the modal dialog (do nothing just allow user to cancel) is a thread spawn by
    Swing event-dispatch thread and block the Swing dispatch-thread until dialog close.
    So my thread can modify Swing GUI stuff safely since there are no any concurrent access problem.
    In this case, I broke the Swing's suggestion, modify Swing stuff out of Swing event-dispatch thread.
    But as I said, there are no concurrent access, so I am safe.
    Am I right? Are you agree? Do you have other better idea?
    Thanks for your help.

    If you drag your modal dialog around in front of the background UI, then there is concurrent access: paint requests in your main window as the foreground window moves around.

  • How to display multiple tables from database using netbeans swing gui

    plz reply asap on how to display multiple tables from database using netbeans swing gui into the same project

    Layered Pane with JTables or you can easily to it with a little scripting and HTML.
    plzzzzzzzzzzzzzzzzz, do not use SMS speak when posting.

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Creating Undo Menu on Swing GUI

    Undo Menu is to be Created on Swing GUI on the Graphics. In the Tutorial, Undo with Text is given. But on implementing the logic of Undo with Text , some Errors come.

    You can use javax.swing.undo.* stuff only with classes implementing
    javax.swing.text.Document interface.
    To add undo/redo functionality for some Graphic components you should program this mechanism by yourself.
    So create your own object model, track all changes and implement/add appropriate listeners.

  • PLease help! GUI and Data Structure

    Hey guys,
    It's for my school project.
    I have to write codes for GUI program for a order form.
    I'm pretty much done with layout and stuff, but I couldn't figure out how to give some regulation(?) on some of the field.
    For instantce, I have to regulate a user to type only two letter abbreviation on state(address) field and the Zip field has to be either 5 digit form or XXXXX-XXXX.
    I Also have to include code to filter the user input and display error message if they enter wrong information.
    Second, how to use actoinevent stuff?
    There are three product type: a,b, and c. If "a" be chosen, then the product name associating the "a" product has to be shown on the product name field(I used ComboBox), and the price for that product(for instance a-1) has to be shown on the price field.
    Third, It sounds stupid question, but how to display current date on the java program using API?
    Fourth, I have to load some of the order from external files(maybe text files) and display into the screen.
    Here is the code
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.ListSelectionEvent;
    class orderFormGUI extends JFrame {
         private JButton bSave, bExit, bLoad;
         private JLabel labelTitle;
         private JTextField fieldFName, fieldLName, fieldStreet, fieldCity,
                   fieldState, fieldZip;
         private JLabel labelFName, labelLName, labelStreet, labelCity, labelState,
                   labelZip;
         private String[] st = { "CA", "TX", "OR", "UT", "NM", "NY", "NY", "GA",
                   "IL", "TN", "MN", "WY" };
         private JComboBox comboPType, comboPName;
         private JLabel labelComboPType, labelComboPName;
         private String[] ct = { "Copmuter", "Printer", "Monitor" };
         private String[] cn = { "CMP1100", "CMP1500" };
         private String[] pn = { "PR500", "PR1000" };
         private String[] mn = { "D4000", "D8000" };
         private String[] x;
         private JTextField fieldTotalPrice, fieldProductPrice;
         private JLabel labelTotalPrice, labelProductPrice;
         private JTextField filedQty;
         private JLabel labelQty;
         private JTextField fieldOrderDate, fieldDeliveryDate;
         private JComboBox comboDeliveryOptions;
         private String[] dO = { "5 Days", "10 Days" };
         private JLabel labelOrderDate, labelDeliveryOptions, labelDeliveryDate;
         private ArrayList orderArray;
         private DefaultListModel lmodel;
         public void initComponents() {
              bSave.setActionCommand("Save");
              bLoad.setActionCommand("Load");
              bExit.setActionCommand("Exit");
              bSave.addActionListener(new ButtonListener());
              bLoad.addActionListener(new ButtonListener());
              bExit.addActionListener(new ButtonListener());
         public void ClearFields() {
              // Set all text fields to blank
              fieldFName.setText("");
              fieldLName.setText("");
              fieldStreet.setText("");
              fieldCity.setText("");
              fieldState.setText("");
              fieldZip.setText("");
         public orderFormGUI() {
              orderArray = new ArrayList();
              bSave = new JButton("Save");
              bLoad = new JButton("Load");
              bExit = new JButton("Exit");
              // set up labels and field size for GUI
              labelTitle = new JLabel("Order Form");
              fieldFName = new JTextField("", 30);
              labelFName = new JLabel("First Name: ");
              fieldLName = new JTextField("", 30);
              labelLName = new JLabel("Last Name: ");
              fieldStreet = new JTextField("", 12);
              labelStreet = new JLabel("Street: ");
              fieldCity = new JTextField("", 12);
              labelCity = new JLabel("City: ");
              fieldState = new JTextField("", 2);
              labelState = new JLabel("State: ");
              fieldZip = new JTextField("", 9);
              labelZip = new JLabel("Zip Code: ");
              comboPType = new JComboBox(ct);
              chooseProductName();
              labelComboPType = new JLabel("Product Type");
              comboPName = new JComboBox();
              labelComboPName = new JLabel("Product Name");
              fieldProductPrice = new JTextField("");
              labelProductPrice = new JLabel("Product Price: ");
              fieldTotalPrice = new JTextField("", 12);
              labelTotalPrice = new JLabel("Total Price: ");
              filedQty = new JTextField("", 12);
              labelQty = new JLabel("Quantity: ");
              fieldOrderDate = new JTextField("", 12);
              labelOrderDate = new JLabel("Order Date: ");
              comboDeliveryOptions = new JComboBox(dO);
              labelDeliveryOptions = new JLabel("Delivery Options: ");
              fieldDeliveryDate = new JTextField("", 12);
              labelDeliveryDate = new JLabel("Delivery Date: ");
              TextFieldHandler handler = new TextFieldHandler();
              fieldState.addActionListener(handler);
              // Construct GUI and set layout
              JPanel mine = new JPanel();
              mine.setLayout(null);
              mine.add(labelTitle);
              labelTitle.setBounds(150, 30, 100, 15);
              mine.add(fieldFName);
              fieldFName.setBounds(88, 80, 220, 21);
              mine.add(labelFName);
              labelFName.setBounds(16, 80, 134, 21);
              mine.add(fieldLName);
              fieldLName.setBounds(88, 110, 220, 21);
              mine.add(labelLName);
              labelLName.setBounds(16, 110, 134, 21);
              mine.add(fieldStreet);
              fieldStreet.setBounds(88, 150, 220, 21);
              mine.add(labelStreet);
              labelStreet.setBounds(16, 150, 134, 21);
              mine.add(fieldCity);
              fieldCity.setBounds(88, 180, 220, 21);
              mine.add(labelCity);
              labelCity.setBounds(16, 180, 134, 21);
              mine.add(fieldState);
              fieldState.setBounds(88, 210, 220, 21);
              mine.add(labelState);
              labelState.setBounds(16, 210, 134, 21);
              mine.add(fieldZip);
              fieldZip.setBounds(88, 240, 220, 21);
              mine.add(labelZip);
              labelZip.setBounds(16, 240, 134, 21);
              mine.add(comboPType);
              comboPType.setBounds(120, 280, 220, 21);
              mine.add(labelComboPType);
              labelComboPType.setBounds(16, 280, 134, 21);
              mine.add(comboPName);
              comboPName.setBounds(120,310, 220, 21);
              mine.add(labelComboPName);
              labelComboPName.setBounds(16, 310, 134, 21);
              mine.add(fieldProductPrice);
              fieldProductPrice.setBounds(120, 340, 220, 21);
              fieldProductPrice.setEditable(false);
              mine.add(labelProductPrice);
              labelProductPrice.setBounds(16, 340, 134, 21);
              mine.add(filedQty);
              filedQty.setBounds(120, 370, 220, 21);
              mine.add(labelQty);
              labelQty.setBounds(16, 370, 134, 21);
              mine.add(fieldOrderDate);
              fieldOrderDate.setBounds(120, 430, 220, 21);
              fieldOrderDate.setEditable(false);
              mine.add(labelOrderDate);
              labelOrderDate.setBounds(16, 430, 134, 21);
              mine.add(comboDeliveryOptions);
              comboDeliveryOptions.setBounds(120, 460, 220, 21);
              mine.add(labelDeliveryOptions);
              labelDeliveryOptions.setBounds(16, 460, 134, 21);
              mine.add(fieldDeliveryDate);
              fieldDeliveryDate.setBounds(120, 490, 220, 21);
              fieldDeliveryDate.setEditable(false);
              mine.add(labelDeliveryDate);
              labelDeliveryDate.setBounds(16, 490, 134, 21);
              mine.add(fieldTotalPrice);
              fieldTotalPrice.setBounds(120, 520, 220, 21);
              fieldTotalPrice.setEditable(false);
              mine.add(labelTotalPrice);
              labelTotalPrice.setBounds(16, 520, 134, 21);
              mine.add(bSave);
              bSave.setBounds(16, 550, 100, 21);
              mine.add(bLoad);
              bLoad.setBounds(130, 550, 100, 21);
              mine.add(bExit);
              bExit.setBounds(250, 550, 100, 21);
              this.setContentPane(mine);
              this.pack();
              this.setTitle("Order Form);
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              setSize(380, 630);
         public void chooseProductName(){
              if ((ct).equals(ct[0])){
                   comboPName = new JComboBox(cn);
              }else if (ct.equals(ct[1])){
                   comboPName = new JComboBox(pn);
              }else if (ct.equals(ct[2])){
                   comboPName = new JComboBox(mn);
         public void comboPNameChanged(ItemEvent event){
              if (event.getStateChange() == ItemEvent.SELECTED);
         private void setTestData() {
              orderArray.add(makeOrder("1-100-1000"));
              orderArray.add(makeOrder("1-100-1001"));
              orderArray.add(makeOrder("1-100-1002"));
              for (Order temp : orderArray) {
                   if (temp.getOrder().equals("1-100-1000")) {
                        temp.setfName("a");
                        temp.setlName("s");
                        temp.setstreet("4802 Alaska Ave");
                        temp.setcity("Cypress");
                        temp.setzip("90630");
         private Order makeOrder(String order) {
              Order temp = new Order(order);
              return temp;
         private void loadDate(){
         String fn;
         JFileChooser fc = new JFileChooser();
         if(fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){
              fn = fc.getSelectedFile().getName();
         if( !new File("objdata.dat").exist() ) {
              setTestData();
              for (Order temp: orderArray());
                   lmodel.addElement(temp.getOrder());)
         class Order {
              String orderid, fName, lName, street, city, state, zip;
              public Order(String order) {
                   orderid = order;
              public String getOrder() {
                   return orderid;
              public String getfName() {
                   return fName;
              public void setfName(String fName) {
                   this.fName = fName;
              public String getlName() {
                   return lName;
              public void setlName(String lName) {
                   this.lName = lName;
              public String getstreet() {
                   return street;
              public void setstreet(String street) {
                   this.street = street;
              public String getcity() {
                   return city;
              public void setcity(String city) {
                   this.city = city;
              public String getzip() {
                   return zip;
              public void setzip(String zip) {
                   this.zip = zip;
         private class TextFieldHandler implements ActionListener {
              public void actionPerformed(ActionEvent event) {
                   String string = " ";
                   if (event.getSource() == fieldState)
                        string = String.format("%s " + "is not correct form.", event
                                  .getActionCommand());
                   JOptionPane.showMessageDialog(null, string);
                   // System.out.println("Please use two letter abbreviation.");
    public class Main {
         public static void main(String[] args) {
              JFrame window = new orderFormGUI();
              window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              window.setVisible(true);
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Cross-posted:
    http://forum.java.sun.com/thread.jspa?messageID=10019967

  • Need help with threading in Swing GUI !!!

    I've written an app that parses and writes
    files. I'm using a Swing GUI. The app
    could potenially be used to parse hundreds or even
    thousands of files. I've included a JProgressBar
    to monitor progress. The problem is when I parse
    a large number of files the GUI freezes and only
    updates the values of the progress bar when the
    parsing and writing process is finished.
    I assume I need to start the process in a seperate thread. But, I'm new to threads and I'm not sure
    whether to start the Progressbar code in a seperate
    thread or the parsing code. As a matter of fact I really
    don't have any idea how to go about this.
    I read that Swing requires repaints be done in the
    event dispatch thread. If I start the parsing in a seperate
    thread how do I update the progressbar from the other
    thread? I'm a thread neophyte.
    I need a cigarette.

    In other words do this:
    Inside event Thread:
    handle button action
    start thread
    return from action listener
    Inside worker Thread:
    lock interface
    loop
    perform action
    update progress bar
    unlock interface
    return from worker ThreadDoesn't updating the progress bar (and locking/unlocking the interface components) from within the worker thread violate the rule that you shouldn't mess with Swing components outside the event thread? (Do I have that rule right?)
    In any case, is there any way to just post some kind of event to the progress bar to update it from within the worker thread, thereby insuring that the GUI progress bar update is being invoked from the event thread? This would also obviate the need to use a timer to poll for an update, which I think is a waste especially when the monitored progress is at a variable rate, (or for number crunching, is executing on different speed machines).
    Also, doesn't using invokeLater() or invokeAndWait() still block the event dispatching thread? I don't understand how having a chunk of code started in the event thread doesn't block the event thread unless the code's executed in a "sub-thread", which would then make it not in the event thread.
    I'm also looking to have a progress bar updated to monitor a worker thread, but also want to include a "Stop" button, etc. and need the event queue not to be blocked.
    The last thing I can think of is to implement some kind of original event-listener class that listens to events that I define, then register it with the system event queue somehow, then have the worker thread post events to this listener which then calls setValue() in the progress bar to insure that the bar is updated from the event queue and when I want it to be updated. I don't know yet if it's possible to create and register these kinds of classes (I'm guessing it is).
    Thanks,
    Derek

  • Separte GUI and application code

    Below is my code to separate GUI and application code. When i try to execute the code i get message applet not initiated. Can any one point what mistake i am doing in the code.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class ColorAction extends AbstractAction
         public ColorAction(String name, Icon icon,Color c, Component comp)
              putValue(Action.NAME, name);
              putValue(Action.SMALL_ICON,icon);
              putValue("Color",c);
              target = comp;
         public void actionPerformed(ActionEvent evt)
              Color c = (Color)getValue("Color");
              target.setBackground(c);
              target.repaint();
         private Component target;
    class ActionButton extends JButton
         public ActionButton(Action a)
              setText((String)a.getValue(Action.NAME));
              Icon icon = (Icon)a.getValue(Action.SMALL_ICON);
              if(icon != null)
                   setIcon(icon);
              addActionListener(a);
    public class SepGUI extends JApplet
         public void init()
              JPanel panel = new JPanel();
              Action blueAction = new ColorAction("Blue",new ImageIcon("a.gif"),Color.blue,panel);
              Action yellowAction = new ColorAction("Yellow",new ImageIcon("a.gif"),Color.yellow,panel);
              Action redAction = new ColorAction("Red",new ImageIcon("a.gif"),Color.red,panel);
              panel.add(new ActionButton(yellowAction));
              panel.add(new ActionButton(blueAction));
              panel.add(new ActionButton(redAction));
              Container contentPane = getContentPane();
              contentPane.add(panel);
    }

    public class SepGUI extends JApplet
      public void init()
        JPanel panel = new JPanel();
        try
          Action blueAction = new ColorAction("Blue",new ImageIcon(new java.net.URL (getCodeBase(),"a.gif")),Color.blue,panel);
          Action yellowAction = new ColorAction("Yellow",new ImageIcon(new java.net.URL (getCodeBase(),"a.gif")),Color.yellow,panel);
          Action redAction = new ColorAction("Red",new ImageIcon(new java.net.URL (getCodeBase(),"a.gif")),Color.red,panel);
          panel.add(new ActionButton(yellowAction));
          panel.add(new ActionButton(blueAction));
          panel.add(new ActionButton(redAction));
        catch(Exception e){}
        Container contentPane = getContentPane();
        contentPane.add(panel);
    }

  • Need to run swing GUIs under different JRE versions

    I need to run swing GUIs under different JRE versions. Where can I find information about how to use only classes which exist from version 1.1.7 and above?

    Under 1.1.7, Swing (then version 1.0) was under com.sun.java.swing. The package name changed in Swing 1.1 b3/JDK 1.2 to javax.swing. You can see what classes were available under Swing 1.0 at http://java.sun.com/products/jfc/swingdoc-api-1.0.3/frame.html

  • Learning swing gui by hand or gui builder?

    Hello,
    Which is a better way of start learning writing swing gui based apps? by hand or using gui builder?
    Do you know any useful web links? or do you consider buying books?
    Thanks.

    >>
    Hmm, the differences:
    1) The GUI builder app resizes correctly.-->>falseJust stating it is false doesn't make it so. I never have any issues with my GUI builder apps resizing correctly. I do have issues making my coded by hand apps resize correctly. Ignorance on my part? Possibly
    I used to use a GUI builder just for complicated layouts and use GridBagLayout for simple dialogs inside an app, but I find myself just using a GUI builder now. Just much quicker and much less hassle.
    As far as maintaining the code if you use the GUI builder for maintanence where is the issue?
    i have never seen a GUI builer that uses
    layoutmangers please point me to the one that you are
    using i would love to take a look
    secondly have you seen tried the little exersise you
    will be suprised at how complex the code is compared
    to the one done by hand!!!!IntelliJ's GUI builder appears to use a custom GridLayout manager, the code it generates appears pretty straightforward to me, doesn't seem overly complicated:
    private void $$$setupUI$$$() {
            mainPanel = new JPanel();
            mainPanel.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
            final JSplitPane splitPane1 = new JSplitPane();
            splitPane1.setContinuousLayout(true);
            splitPane1.setDividerLocation(142);
            mainPanel.add(splitPane1, new com.intellij.uiDesigner.core.GridConstraints(0, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_BOTH, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, null, new Dimension(200, 200), null));
            fileListing = new JTree();
            splitPane1.setLeftComponent(fileListing);
            tabPane = new JTabbedPane();
            splitPane1.setRightComponent(tabPane);
            renameTab = new JPanel();
            renameTab.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(2, 7, new Insets(0, 0, 0, 0), -1, -1));
            tabPane.addTab("Untitled", renameTab);
            final JLabel label1 = new JLabel();
            label1.setHorizontalAlignment(4);
            label1.setText("Current Filename");
            renameTab.add(label1, new com.intellij.uiDesigner.core.GridConstraints(1, 0, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_WEST, com.intellij.uiDesigner.core.GridConstraints.FILL_NONE, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null));
            imageScrollPane = new JScrollPane();
            imageScrollPane.setHorizontalScrollBarPolicy(30);
            imageScrollPane.setVerticalScrollBarPolicy(20);
            renameTab.add(imageScrollPane, new com.intellij.uiDesigner.core.GridConstraints(0, 0, 1, 7, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_BOTH, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null));
            currentFilenameField = new JTextField();
            renameTab.add(currentFilenameField, new com.intellij.uiDesigner.core.GridConstraints(1, 1, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_WEST, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null));
            final JLabel label2 = new JLabel();
            label2.setText("New Filename");
            renameTab.add(label2, new com.intellij.uiDesigner.core.GridConstraints(1, 2, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_WEST, com.intellij.uiDesigner.core.GridConstraints.FILL_NONE, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null));
            newFilenameField = new JTextField();
            renameTab.add(newFilenameField, new com.intellij.uiDesigner.core.GridConstraints(1, 3, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_WEST, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_WANT_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null));
            renameButton = new JButton();
            renameButton.setText("Rename");
            renameTab.add(renameButton, new com.intellij.uiDesigner.core.GridConstraints(1, 4, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null));
            previousButton = new JButton();
            previousButton.setText("");
            renameTab.add(previousButton, new com.intellij.uiDesigner.core.GridConstraints(1, 5, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null));
            nextImageButton = new JButton();
            nextImageButton.setText("");
            renameTab.add(nextImageButton, new com.intellij.uiDesigner.core.GridConstraints(1, 6, 1, 1, com.intellij.uiDesigner.core.GridConstraints.ANCHOR_CENTER, com.intellij.uiDesigner.core.GridConstraints.FILL_HORIZONTAL, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_SHRINK | com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_CAN_GROW, com.intellij.uiDesigner.core.GridConstraints.SIZEPOLICY_FIXED, null, null, null));
            htmlGeneratorTab = new JPanel();
            tabPane.addTab("Untitled", htmlGeneratorTab);
        }

Maybe you are looking for

  • Is there a way to make the iPod Nano 7 run smoother?

    I love the iPod Nano. It's great. I've had mine for something like two years now, and I love it. But lately it's been acting up. It connects to my docking station, but if you touch the iPod in anyway, it will immediately disconnect and stop playing m

  • Profit Center Standard Hierarchy  in Production Server

    Dear All I have done Controlling Area Settings for Profit Centers via TCode: 0KE5. I have made Profit Center Standard Hierarchy in Development server. The same Standard hierarchy is available in Quality sever but it is unavaliable in Production serve

  • Different archivelog destination on physical standby database

    Hi, Can I set different archivelog destination for physical standby database in duplicate command? (Due to space problem ) How can I do it? For ex. on primary site archivelogs reside in /u01/ORCL/archivelog, and I want on phy. standby side archive de

  • Failure 1 contacting cssd daemon

    HI we have solaris server10 - 2 node RAC db with 10.2.0.4 version . When i check crsctl check crs , the output is showing as crsctl check crs Failure 1 contacting CSS daemon CRS appears healthy EVM appears healthy when i check crs_stat -t -v , the ou

  • Single Mailbox receiving 432-4.3.2 STOREDRV; mailbox server is too busy error emailing distribution group

    I have a user who is trying to email a distribution group with approximately 185 recipients, 183 internal, and 2 external. The user is recieving message delayed/pending for some (but not all) of the recipients. Approximately 15 recipients have reciev