0

I am trying to open up an JFrame with an gif-loading animation from another JFrame. The problem is, that the new JFrame opens but the gif animations just shows up if the loading time is over, so there is a empty JFrame during the whole loading sequence.

I am trying to open up my new JFrame in my current JFrame like this:

Ladescreen loading = new Ladescreen();
loading.setVisible(true);
loading.pack();

And this is how my Loadingscreen is built:

public Ladescreen() {
        setTitle("Crawling through files...");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 157, 207);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);

        JPanel panel = new JPanel();
        contentPane.add(panel, BorderLayout.NORTH);
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

        JLabel picture = new JLabel();
        picture.setIcon(new ImageIcon("football.gif"));
        panel.add(picture);


        JPanel panel_1 = new JPanel();
        contentPane.add(panel_1, BorderLayout.SOUTH);

        JLabel lblNewLabel = new JLabel("Loading...");
        panel_1.add(lblNewLabel);
    }

Can you tell me how to fix this up ?

  • 3
    If it's supposed to display during a long standing operation, the issue is that the event dispatch thread is blocked. Long lasting tasks should be done in a background thread; Using a [SwingWorker](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html) is usually the simplest. – kiheru Jul 21 '15 at 12:19
  • 2
    As general advice (not sure it is applicable here): 1) Don't block the EDT (Event Dispatch Thread). The GUI will 'freeze' when that happens. See [Concurrency in Swing](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/) for details and the fix. 2) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 3) For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). – Andrew Thompson Jul 21 '15 at 12:19
  • Seeing as this isn't the full code, running it on my Eclipse doesn't do anything. And I am going to assume you have made some of your own methods, as setBounds is actually also a .bounds(...) option for the contentPane. Also, try inserting all you need into your content pane last. I believe it was .addAll – SomeStudent Jul 21 '15 at 12:29
  • @kiheru could you maybe form an answer witha few tips more ? In addition I can mark it as answered – MegaCleptomaniac Jul 21 '15 at 12:37

0 Answers0