0

I have an applet with a main view and multiple additional pop-up JFrames. One JFrame (Report() ) takes more than 20 seconds to load because of an SQL query. I would like to display a pop-up JFrame which would warn the user, that the requested window is loading, but the content of the pop-up JFrame is displayed only after the asked JFrame was loaded.

This is the code that I have:

JFrame frame = new JFrame("Loading");

JLabel label = new JLabel("My label");
label.setFont(new java.awt.Font("Arial", 1, 16));
label.setText("<html> Please wait while </br> report loads </br>");
JPanel top = new JPanel();
top.add(label);
top.setBackground(Color.WHITE);

frame.add(top);
frame.setBackground(Color.WHITE);
frame.pack();
frame.setSize(200, 200);
frame.setVisible(true);

new Report();

In Report I do not have a main() method, I initialize it from the constructor directly with:

    // setting up the cross-platform look and feel
    preInitComponents();
    // setting up the UI
    initComponents();
    // visualizing the jframe
    pack();
    setVisible(true);

Any suggestions what am I doing wrong?

sboda
  • 363
  • 4
  • 10
  • Why not use JOptionPane? https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html – Reinard May 11 '16 at 11:29
  • USing swingutilities.invokelater should fix the problem btw. – Reinard May 11 '16 at 11:30
  • I would like to customize it maybe further later. Probably a progress bar would be the ideal solution, but that still would be placed on a JFrame – sboda May 11 '16 at 11:31
  • 2
    Start by having a look at [Concurrency in Swing](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/) for more information about the problem you're trying to solve and [Worker Threads and SwingWorker](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html) for a possible way to solve it – MadProgrammer May 11 '16 at 11:33
  • 1
    For [example](http://stackoverflow.com/questions/14113644/java-global-reusable-loading-dialog/14114663#14114663) ... although you probably don't need the progress bar ;) – MadProgrammer May 11 '16 at 11:34
  • @MadProgrammer thanks, will try to understand and implement your solution – sboda May 11 '16 at 11:48
  • @MadProgrammer thanks, your example did the trick... – sboda May 11 '16 at 12:25

0 Answers0