#6026 HIGH Never A: Matchbox won't show a Java/Swing window

Zarro Boogs per Child bugtracker at laptop.org
Tue Jan 15 14:30:28 EST 2008


#6026: Matchbox won't show a Java/Swing window
--------------------+-------------------------------------------------------
 Reporter:  skim    |       Owner:  marco         
     Type:  defect  |      Status:  new           
 Priority:  high    |   Milestone:  Never Assigned
Component:  sugar   |     Version:                
 Keywords:          |    Verified:  0             
 Blocking:          |   Blockedby:                
--------------------+-------------------------------------------------------
 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);
         }
     }
 }
 }}}

-- 
Ticket URL: <http://dev.laptop.org/ticket/6026>
One Laptop Per Child <http://dev.laptop.org>
OLPC bug tracking system



More information about the Bugs mailing list