0

I've got several unrelated swing classes that are instances of JFrame. The issue is, I'd like to be able to create a controller class with a static method to load the appropriate frames as needed. I'm experiencing difficulty with the following code as many of components are failing to load. I suspect that the issue is with the event dispatch thread. Below is the code that doesn't work:

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Controller {

    private Controller() {
    }

    public static void initialize(final JFrame frame) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame selectionFrame = frame;
            }
        });

    }

    public static void main(String[] args) {

        Controller.initialize(new SampleFrame());

    }

}

The program loads the frame and toolbar components but other components fail to load. NOTE: The program runs just fine if I refactor the Controller like so :

public class Controller {

    public static void main(String[] args) {

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new SampleFrame();
            }
        });

    }

}
Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
jrreid
  • 81
  • 1
  • 3

0 Answers0