0

I've got one simple frame to display during a method execution with only one panel with two components.

So this is my code :

public void sarPPRuning() {
    JProgressBar progressBar = new JProgressBar();
    progressBar.setIndeterminate(true);

    sarppRun = new JFrame("Please wait");
    JPanel pan = new JPanel(new GridBagLayout());
    pan.add(new JLabel("SARPP is running, please wait"),
            new GridBagConstraints(0, 0, 1, 1, 1, 1,
                    GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3),
                    0, 0));
    pan.add(progressBar, new GridBagConstraints(0, 1, 1, 1, 1, 1,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
            new Insets(3, 3, 3, 3), 0, 0));
    sarppRun.getContentPane().add(pan, BorderLayout.CENTER);
    sarppRun.setSize(400, 100);
    sarppRun.setVisible(true);
    sarppRun.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

This method is called here:

_vet.sarPPRuning();
execSARPP()

Where _vet is an instance of a class which extends ViewGuiDialog

My JFrame appears, but it is empty until the execSARPP function is finished !!!

tmarwen
  • 15,750
  • 5
  • 43
  • 62
  • Your code works for me. I had to change the third line to `JFrame sarppRun = new JFrame("Please wait");` though. But as I think you've declarated the variable earlier, I don't find the error. Maybe it's just appearing too short for you to see anything? I tried to run it standalone in a main-function and it worked. – Loki Aug 20 '14 at 13:24
  • I don't know either, it renders fine here. – Elliott Frisch Aug 20 '14 at 13:26
  • I don't think so because the JFrame appears during a certain time (until I call the method setVisible(false) after in my program...). But empty – user3699747 Aug 20 '14 at 13:27
  • You probably need to show more code for us to figure out the problem, as I assume its nowhere within the lines you provided already. – Loki Aug 20 '14 at 13:31
  • 2
    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – DavidPostill Aug 20 '14 at 13:31
  • I have just edited my question I don't know if it can help you... – user3699747 Aug 20 '14 at 13:39
  • Put the execSARPP() method code into your question, and yes, if you call setVisible(false) it will stop showing your Frame. – Adam Aug 20 '14 at 17:40
  • I agree with @DavidPostill. We don't need disparate snippets pf code, but an (minimal) runnable example. 1) See also [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 2) **Use `pack()` instead of `setSize(..)` for the frame.** – Andrew Thompson Aug 21 '14 at 00:32

1 Answers1

1

When I take your code and run it by itself,

public static void main(String[] args) {
    JProgressBar progressBar = new JProgressBar();
    progressBar.setIndeterminate(true);

    JFrame sarppRun = new JFrame("Please wait");
    JPanel pan = new JPanel(new GridBagLayout());
    pan.add(new JLabel("SARPP is running, please wait"),
            new GridBagConstraints(0, 0, 1, 1, 1, 1,
                    GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, new Insets(3, 3, 3, 3),
                    0, 0));
    pan.add(progressBar, new GridBagConstraints(0, 1, 1, 1, 1, 1,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
            new Insets(3, 3, 3, 3), 0, 0));
    sarppRun.getContentPane().add(pan, BorderLayout.CENTER);
    sarppRun.setSize(400, 100);
    sarppRun.setVisible(true);
    sarppRun.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

It works as expected and I get the JFrame with a moving progress bar, SARPP JFrame

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249