JDesktop/JInternalFrame Updating?
I am wondering if anyone can give me a pointer on a problem that I am having with the JDesktop. What I am trying to do is provide feedback to the user during a long load operation by displaying a temporary JInternalFrame tha contains a status message. The attached code simulates the problem. When the user clicks on the "Load" option under the File menu, I want to display a message in a frame to tell the user that the load operation has begun (and to be patient).
What happens, is that the load begins (simulated in this code by an endless loop), but the File/Load menu option fails to clear, and the JInternalFrame is not displayed.
Any help would be greatly appreciated.
Richard
/******************/
/* Sample Code */
/******************/
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.*;
public class Test extends JFrame
{
JDesktopPane desktop;
public Test()
{
super("Test");
int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset,
screenSize.width - inset*2,
screenSize.height - inset*2);
//Set up the GUI.
desktop = new JDesktopPane();
setContentPane(desktop);
setJMenuBar(AddMenu());
}
public JMenuBar AddMenu()
{
JMenuBar bar = new JMenuBar();
JMenu FileMenu = CreateFileMenu();
bar.add(FileMenu);
return bar;
}
protected JMenu CreateFileMenu()
{
final JMenu menu = new JMenu("File");
menu.add(new SelectableMenuItem("Load"));
return menu;
}
protected class SelectableMenuItem extends JMenuItem
implements ActionListener
{
public SelectableMenuItem(String item)
{
super(item);
addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
JMenuItem item = (JMenuItem) e.getSource();
if (item.getText()=="Load")
{
Load();
}
}
}
public void Load()
{
JInternalFrame StatusFrame=new JInternalFrame("Loading Project", true, false, true, false);
StatusFrame.getContentPane().add(new JLabel("LOADING PROJECT!"));
desktop.add(StatusFrame);
try
{
StatusFrame.reshape(0,0,200,200);
StatusFrame.setVisible(true);
}
catch(Exception ea)
{
System.out.println(ea.getMessage());
}
int x=0;
while(x==0)
{
// simulating a long load of some data
System.out.println("Loading data...");
}
}
public static void main(String[] args) throws Exception {
try
{
UIManager.setLookAndFeel(
"javax.swing.plaf.metal.MetalLookAndFeel");
}
catch (Exception e) { }
Test test=new Test();
test.setVisible(true);
}
}

