1

I am using Swing with JDK1.7 and I want to achieve very simple task. I want to open a Frame within seperate Thread on one Button Click. For this i have designed a class called TestThread.

public class TestThread implements Runnable {
    public TestThread() {
        super();
    }

private int target = 100;

    public void setTarget(int target) {
        this.target = target;
    }

    public int getTarget() {
        return target;
    }

    @Override
    public void run() {
        setFrame();
    }

    public void setFrame() {
        JFrame frame = new JFrame("Test");
        frame.setVisible(true);

    }
}

and on button click one new thread is created and launched with ProgressMonitor component. Now the problem is after open Frame progressMonitor does not closed. It continues runnning forever. I found launcher thread is not getting closed that's why progressMonitor is going on.

Can someone tell me what's wrong with this code.

  private void jButton_actionPerformed(ActionEvent e) {
    BaseApp.mode = irisApp.mode;
    BaseApp.getInstance().setUser(irisApp.getUser());



        TestThread test = new TestThread();

        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));


        progressDialog = new ProgressMonitor(this,
        "Please wait while system is loading",null, 0, test.getTarget());
        progressDialog.setProgress(0);

        corpActivityMonitor.setDelay(0);
        corpActivityMonitor.start();

    Thread thread = new Thread(test);

          thread.start();
        jButtonCorporation.requestFocus();

      }
    }
 }
keepmoving
  • 1,813
  • 8
  • 34
  • 74
  • *"I want to open a Frame within seperate Thread on one Button Click"* - Don't. Swing is a single threaded framework, it is also not thread safe. You should only create and update UI components from within the context of the Event Dispatching Thread. See [Concurrency in Swing](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/) for more details – MadProgrammer Dec 02 '15 at 11:02
  • @Naveen where you close() your progressbar – Tom Sebastian Dec 02 '15 at 11:42
  • See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Dec 02 '15 at 13:12

0 Answers0