Problem running a java/swing application

Seong-June Kim skim at concord.org
Tue Jan 15 16:46:03 EST 2008


Hi, I have created a ticket for this problem
(http://dev.laptop.org/ticket/6026) but I thought there may be
some people here that can give me some insights, and hopefully
also some that are willing to examine the problem,
so I reproduce it below:

I tried a minimal Java/Swing application with the following code
and found that either setLocation() or setSize() must be called
AFTER setVisible(True) for the window to show itself correctly.

Otherwise, if either none of the setLocation() and setSize() were
called or if they were called BEFORE setVisible(), Sugar would hang
with a blank screen. The values for location and/or size didn't
make any difference.

Normally the order of the method calls shouldn't matter. I ran
the matchbox window manager on Ubuntu Linux and it didn't have
the problem there.

I saw this problem with both java 5 and java 6, on build 623
and jhbuild.


import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;

public class SwingTest extends JFrame {
    JMenuBar menuBar;

    public static void main(String[] args) {
        SwingTest viewer = new SwingTest();
    }

    public SwingTest() {
	super();
	setTitle("Swing Test");
	updateMenuBar();
	setJMenuBar(menuBar);

	setVisible(true); // works!
	setLocation(10, 10);
	//setVisible(true); // breaks!
    }

    public JMenuBar updateMenuBar() {
        JMenu fileMenu = null;
        if (menuBar == null) {
            menuBar = new JMenuBar();
	    fileMenu = new JMenu("File");
	    menuBar.add(fileMenu);
        } 
        else {
            fileMenu = menuBar.getMenu(0);
	    fileMenu.removeAll();
        }
        fileMenu.add(new ExitAction());
        return menuBar;
    }

    class ExitAction extends AbstractAction {
	private static final long serialVersionUID = 1L;

	public ExitAction() {
	    super("Exit");
	}

	public void actionPerformed(ActionEvent e) {
	    System.exit(0);
	}
    }
}




More information about the Devel mailing list