I try to create and show a GUI and to populate later a DefaultComboBoxModel using SwingUtilities.invokeLater(...).
But the UI is still freezing and components are not displayed until the loading thread has completed.
The main frame is instantiated by Spring application context.Building/showing GUI through "fullInitialize" method called by Spring after frame initialization has completed (see method code below).
<bean id="view" class="be.philippefery.bigmap.view.MainView" init-method="fullInitialize">
<constructor-arg index="0" ref="applicationTitle" />
<property name="i18n" ref="i18n" />
<property name="progressListener" ref="progressBar" />
<property name="jb_importGpx" ref="gpxImport" />
<property name="jb_importPointsOfInterest" ref="poisImport" />
<property name="jp_gpxList" ref="gpxFilteredTablePanel" />
<property name="jp_poiList" ref="poiFilteredTablePanel" />
</bean>
MainView class (MainView extends JFrame):
private void fullInitialize() throws IOException {
//Creating the UI here
//This includes a JList and its model which should be populated later (see below)
createAndShowGUI();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
//Time consuming task sending HTTP requests to check if a list of servers are available
//then filling a listModel instantiated through createAndShowGUI() method
initializeTilesServerList();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
private void createAndShowGUI() throws IOException {
this.initialize();
this.jsonUtils = new JsonUtils();
this.createComponents();
this.buildLayout();
pack();
setVisible(true);
}
The problem I'm having is that, even when populating the list using SwingUtilities.invokeLater(...), the UI isn't displayed until this thread is terminated.
This is what is displayed while SwingUtilities.invokeLater(...) is running:
while thread is running
... and once terminated: once thread terminated
Any idea?