Ticket #6026 (new defect)
Matchbox won't show a Java/Swing window
| Reported by: | skim | Owned by: | marco |
|---|---|---|---|
| Priority: | high | Milestone: | 9.1.0-cancelled |
| Component: | sugar | Version: | |
| Keywords: | 9.1.0:? | Cc: | mallum, stepheneb |
| Action Needed: | Verified: | no | |
| Deployments affected: | Blocked By: | ||
| Blocking: |
Description
I thought I'd create a new ticket although this is perhaps remotely related to #907 and #5132.
I tried a minimal Java/Swing application with the following code on jhbuild, 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(), the Sugar would hang with a blank screen.
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);
}
}
}


