[gui][Patch] JMenuBar

Olga Rodimina rodimina@redhat.com
Thu May 20 23:48:00 GMT 2004


Hi, 

Here is the patch that implements part of JMenuBar and 
fixes few problems with positioning of JPopupMenu.

Olga.
-------------- next part --------------
? .snprj
? libjava.proj
? patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2660.2.106
diff -c -p -u -r1.2660.2.106 ChangeLog
--- ChangeLog	18 May 2004 22:56:37 -0000	1.2660.2.106
+++ ChangeLog	20 May 2004 15:04:42 -0000
@@ -1,3 +1,18 @@
+2004-05-18  Olga Rodimina  <rodimina@redhat.com>
+
+	* Makefile.am: Added new file. 
+	* Makefile.in: Regenerate.
+	* javax/swing/JMenuBar.java:
+	Started implementation.
+	* javax/swing/JPopupMenu.java:
+	(setVisible): Fixed location of lightweight/mediumweight
+	popup menu.
+	(show): Fixed location of PopupMenu.
+	* javax/swing/plaf/basic/BasicMenuBarUI.java:
+	New file. UI Delegate for JMenuBar.
+	* javax/swing/plaf/basic/BasicMenuUI.MouseInputHandler:
+	mouseEntered: corrected position of the submenu.
+
 2004-05-18  Thomas Fitzsimmons  <fitzsim@redhat.com>
 
 	* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMenuPeer.c: Remove calls
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.361.2.12
diff -c -p -u -r1.361.2.12 Makefile.am
--- Makefile.am	18 May 2004 14:31:15 -0000	1.361.2.12
+++ Makefile.am	20 May 2004 15:04:42 -0000
@@ -1252,6 +1252,7 @@ javax/swing/plaf/basic/BasicGraphicsUtil
 javax/swing/plaf/basic/BasicLabelUI.java \
 javax/swing/plaf/basic/BasicListUI.java \
 javax/swing/plaf/basic/BasicMenuUI.java \
+javax/swing/plaf/basic/BasicMenuBarUI.java \
 javax/swing/plaf/basic/BasicMenuItemUI.java \
 javax/swing/plaf/basic/BasicOptionPaneUI.java \
 javax/swing/plaf/basic/BasicPanelUI.java \
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.385.2.12
diff -c -p -u -r1.385.2.12 Makefile.in
--- Makefile.in	18 May 2004 14:31:18 -0000	1.385.2.12
+++ Makefile.in	20 May 2004 15:04:43 -0000
@@ -957,6 +957,7 @@ javax/swing/plaf/basic/BasicGraphicsUtil
 javax/swing/plaf/basic/BasicLabelUI.java \
 javax/swing/plaf/basic/BasicListUI.java \
 javax/swing/plaf/basic/BasicMenuUI.java \
+javax/swing/plaf/basic/BasicMenuBarUI.java \
 javax/swing/plaf/basic/BasicMenuItemUI.java \
 javax/swing/plaf/basic/BasicOptionPaneUI.java \
 javax/swing/plaf/basic/BasicPanelUI.java \
@@ -3004,6 +3005,7 @@ javax/swing/plaf/basic/BasicGraphicsUtil
 javax/swing/plaf/basic/BasicLabelUI.lo \
 javax/swing/plaf/basic/BasicListUI.lo \
 javax/swing/plaf/basic/BasicMenuUI.lo \
+javax/swing/plaf/basic/BasicMenuBarUI.lo \
 javax/swing/plaf/basic/BasicMenuItemUI.lo \
 javax/swing/plaf/basic/BasicOptionPaneUI.lo \
 javax/swing/plaf/basic/BasicPanelUI.lo \
@@ -5098,6 +5100,7 @@ DEP_FILES =  .deps/$(srcdir)/$(CONVERT_D
 .deps/javax/swing/plaf/basic/BasicLabelUI.P \
 .deps/javax/swing/plaf/basic/BasicListUI.P \
 .deps/javax/swing/plaf/basic/BasicLookAndFeel.P \
+.deps/javax/swing/plaf/basic/BasicMenuBarUI.P \
 .deps/javax/swing/plaf/basic/BasicMenuItemUI.P \
 .deps/javax/swing/plaf/basic/BasicMenuUI.P \
 .deps/javax/swing/plaf/basic/BasicOptionPaneUI.P \
Index: javax/swing/JMenuBar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JMenuBar.java,v
retrieving revision 1.2
diff -c -p -u -r1.2 JMenuBar.java
--- javax/swing/JMenuBar.java	11 Jun 2003 13:20:39 -0000	1.2
+++ javax/swing/JMenuBar.java	20 May 2004 15:04:44 -0000
@@ -1,4 +1,4 @@
-/* JMenuBar.java -- 
+/* JMenuBar.java --
    Copyright (C) 2002 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
@@ -35,17 +35,392 @@ this exception to your version of the li
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
-
 package javax.swing;
 
+import java.awt.Color;
 import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Insets;
+import java.awt.Point;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
 import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+import javax.accessibility.AccessibleSelection;
+import javax.accessibility.AccessibleStateSet;
+import javax.accessibility.AccessibleValue;
+import javax.swing.UIManager;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.MenuDragMouseEvent;
+import javax.swing.event.MenuDragMouseListener;
+import javax.swing.event.MenuKeyEvent;
+import javax.swing.event.MenuKeyListener;
+import javax.swing.plaf.MenuBarUI;
+import javax.swing.plaf.MenuItemUI;
+
 
-public class JMenuBar extends JComponent
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision$
+ */
+public class JMenuBar extends JComponent implements Accessible, MenuElement
 {
-  JMenuBar()
-    {
-    }
+  private transient SingleSelectionModel selectionModel;
+  private boolean paintBorder;
+  private Insets margin;
+
+  /**
+   * Creates a new JMenuBar object.
+   */
+  public JMenuBar()
+  {
+    selectionModel = new DefaultSingleSelectionModel();
+    paintBorder = true;
+    updateUI();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param c DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public JMenu add(JMenu c)
+  {
+    c.setAlignmentX(Component.LEFT_ALIGNMENT);
+    super.add(c);
+    return c;
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  public void addNotify()
+  {
+    // FIXME: Should register this menu bar with the keyboard manager     
+    super.addNotify();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public AccessibleContext getAccessibleContext()
+  {
+    return null;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public Component getComponent()
+  {
+    return this;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param i DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public Component getComponentAtIndex(int i)
+  {
+    return getComponentAt(i);
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param c DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public int getComponentIndex(Component c)
+  {
+    Component[] comps = getComponents();
+
+    int index = -1;
+
+    for (int i = 0; i < comps.length; i++)
+      {
+	if (comps[i].equals(c))
+	  {
+	    index = i;
+	    break;
+	  }
+      }
+
+    return index;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public JMenu getHelpMenu()
+  {
+    return null;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public Insets getMargin()
+  {
+    if (margin == null)
+      return new Insets(0, 0, 0, 0);
+    else
+      return margin;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param index DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public JMenu getMenu(int index)
+  {
+    if (getComponentAtIndex(index) instanceof JMenu)
+      return (JMenu) getComponentAtIndex(index);
+    else
+      return null;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public int getMenuCount()
+  {
+    return getComponentCount();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public SingleSelectionModel getSelectionModel()
+  {
+    return selectionModel;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public MenuElement[] getSubElements()
+  {
+    MenuElement[] subElements = new MenuElement[getComponentCount()];
+
+    for (int i = 0; i < getComponentCount(); i++)
+      subElements[i] = (MenuElement) getMenu(i);
+
+    return subElements;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public MenuBarUI getUI()
+  {
+    return (MenuBarUI) ui;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public String getUIClassID()
+  {
+    return "MenuBarUI";
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public boolean isBorderPainted()
+  {
+    return paintBorder;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public boolean isManagingFocus()
+  {
+    return true;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public boolean isSelected()
+  {
+    return false;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param isIncluded DOCUMENT ME!
+   */
+  public void menuSelectionChanged(boolean isIncluded)
+  {
+    // Do nothing - needed for implementation of MenuElement interface
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param g DOCUMENT ME!
+   */
+  protected void paintBorder(Graphics g)
+  {
+    if (paintBorder)
+      getBorder().paintBorder(this, g, 0, 0, getSize(null).width,
+                              getSize(null).height);
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  protected String paramString()
+  {
+    return "JMenuBar";
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param e DOCUMENT ME!
+   * @param path DOCUMENT ME!
+   * @param manager DOCUMENT ME!
+   */
+  public void processKeyEvent(KeyEvent e, MenuElement[] path,
+                              MenuSelectionManager manager)
+  {
+    // Do nothing - needed for implementation of MenuElement interface
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param event DOCUMENT ME!
+   * @param path DOCUMENT ME!
+   * @param manager DOCUMENT ME!
+   */
+  public void processMouseEvent(MouseEvent event, MenuElement[] path,
+                                MenuSelectionManager manager)
+  {
+    // Do nothing - needed for implementation of MenuElement interface
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  public void removeNotify()
+  {
+    // Must unregister this menu bar with the current keyboard manager.
+    super.removeNotify();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param b DOCUMENT ME!
+   */
+  public void setBorderPainted(boolean b)
+  {
+    paintBorder = b;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param menu DOCUMENT ME!
+   */
+  public void setHelpMenu(JMenu menu)
+  {
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param m DOCUMENT ME!
+   */
+  public void setMargin(Insets m)
+  {
+    this.margin = m;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param sel DOCUMENT ME!
+   */
+  public void setSelected(Component sel)
+  {
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param model DOCUMENT ME!
+   */
+  public void setSelectionModel(SingleSelectionModel model)
+  {
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param ui DOCUMENT ME!
+   */
+  public void setUI(MenuBarUI ui)
+  {
+    super.setUI(ui);
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  public void updateUI()
+  {
+    MenuBarUI ui = ((MenuBarUI) UIManager.getUI(this));
+    setUI(ui);
+    invalidate();
+  }
 }
Index: javax/swing/JPopupMenu.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JPopupMenu.java,v
retrieving revision 1.3.8.2
diff -c -p -u -r1.3.8.2 JPopupMenu.java
--- javax/swing/JPopupMenu.java	18 May 2004 14:31:21 -0000	1.3.8.2
+++ javax/swing/JPopupMenu.java	20 May 2004 15:04:44 -0000
@@ -63,6 +63,7 @@ import javax.accessibility.AccessibleCon
 import javax.accessibility.AccessibleRole;
 import javax.swing.event.PopupMenuEvent;
 import javax.swing.event.PopupMenuListener;
+import java.applet.Applet;
 import javax.swing.plaf.PopupMenuUI;
 
 
@@ -511,8 +512,20 @@ public class JPopupMenu extends JCompone
 	    else
 	      popup = new HeavyWeightPopup(this);
 	  }
-
-	popup.show(locationX, locationY, size.width, size.height);
+	
+        if (popup instanceof LightWeightPopup 
+            || popup instanceof MediumWeightPopup)
+          {
+            JLayeredPane layeredPane;
+            layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane();
+            Point lp = layeredPane.getLocationOnScreen();
+            Point r = SwingUtilities.getRoot(invoker).getLocationOnScreen();
+            int px = locationX - (lp.x - r.x);
+            int py = locationY - (lp.y - r.y);	  
+            popup.show(px, py, size.width, size.height);	  		
+          } 
+        else
+          popup.show(locationX, locationY, size.width, size.height);
       }
     else
       {
@@ -573,7 +586,15 @@ public class JPopupMenu extends JCompone
   public void show(Component component, int x, int y)
   {
     setInvoker(component);
-    setLocation(invoker.getLocation().x + x, invoker.getLocation().y + y);
+
+    Point rootOnScreen;
+    rootOnScreen = SwingUtilities.getRoot(invoker).getLocationOnScreen();
+    Point invokerOnScreen = invoker.getLocationOnScreen();
+    
+    int popupX = (invokerOnScreen.x - rootOnScreen.x) + x;
+    int popupY = (invokerOnScreen.y - rootOnScreen.y) + y;
+    
+    setLocation(popupX , popupY);
     setVisible(true);
   }
 
Index: javax/swing/plaf/basic/BasicMenuBarUI.java
===================================================================
RCS file: javax/swing/plaf/basic/BasicMenuBarUI.java
diff -N javax/swing/plaf/basic/BasicMenuBarUI.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ javax/swing/plaf/basic/BasicMenuBarUI.java	20 May 2004 15:04:44 -0000
@@ -0,0 +1,277 @@
+/* BasicMenuUI.java
+   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.swing.plaf.basic;
+
+import java.awt.event.ContainerEvent;
+import java.awt.event.ContainerListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.awt.Dimension;
+import javax.swing.BoxLayout;
+import javax.swing.ButtonModel;
+import javax.swing.Icon;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JComponent;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.KeyStroke;
+import javax.swing.MenuElement;
+import javax.swing.MenuSelectionManager;
+import javax.swing.SwingUtilities;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.MenuDragMouseEvent;
+import javax.swing.event.MenuDragMouseListener;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuKeyEvent;
+import javax.swing.event.MenuKeyListener;
+import javax.swing.event.MenuListener;
+import javax.swing.event.MouseInputListener;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.MenuBarUI;
+import javax.swing.plaf.MenuItemUI;
+import java.awt.Insets;
+import java.awt.GridLayout;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision: 1.1.2.7 $
+ */
+public class BasicMenuBarUI extends MenuBarUI
+{
+  protected ChangeListener changeListener;
+  protected ContainerListener containerListener;
+  protected PropertyChangeListener propertyChangeListener;
+  protected JMenuBar menuBar;
+
+  /**
+   * Creates a new BasicMenuBarUI object.
+   */
+  public BasicMenuBarUI()
+  {
+    changeListener = createChangeListener();
+    containerListener = createContainerListener();
+    propertyChangeListener = new PropertyChangeHandler();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  protected ChangeListener createChangeListener()
+  {
+    return new ChangeHandler();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  protected ContainerListener  createContainerListener()
+  {
+    return new ContainerHandler();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param x DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public static ComponentUI createUI(JComponent x)
+  {
+    return new BasicMenuBarUI();
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param c DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public Dimension getMaximumSize(JComponent c)
+  {
+    // let layout manager calculate its size
+    return null;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param c DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public Dimension getMinimumSize(JComponent c)
+  {
+    // let layout manager calculate its size
+    return null;
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param c DOCUMENT ME!
+   *
+   * @return DOCUMENT ME!
+   */
+  public Dimension getPreferredSize(JComponent c)
+  {
+    // let layout manager calculate its size
+    return null;
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  protected void installDefaults()
+  {
+    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+
+    menuBar.setBackground(defaults.getColor("MenuBar.background"));
+    menuBar.setBorder(defaults.getBorder("MenuBar.border"));
+    menuBar.setFont(defaults.getFont("MenuBar.font"));
+    menuBar.setForeground(defaults.getColor("MenuBar.foreground"));
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  protected void installKeyboardActions()
+  {
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  protected void installListeners()
+  {        
+    menuBar.addContainerListener(containerListener);
+    menuBar.addPropertyChangeListener(propertyChangeListener);    
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param c DOCUMENT ME!
+   */
+  public void installUI(JComponent c)
+  {
+    super.installUI(c);
+    menuBar = (JMenuBar) c;
+    menuBar.setLayout(new BoxLayout(menuBar, BoxLayout.X_AXIS));
+    installDefaults();
+    installListeners();
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  protected void uninstallDefaults()
+  {
+    menuBar.setBackground(null);
+    menuBar.setBorder(null);
+    menuBar.setFont(null);
+    menuBar.setForeground(null);
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  protected void uninstallKeyboardActions()
+  {
+  }
+
+  /**
+   * DOCUMENT ME!
+   */
+  protected void uninstallListeners()
+  {
+    menuBar.removeContainerListener(containerListener);
+    menuBar.removePropertyChangeListener(propertyChangeListener);
+  }
+
+  /**
+   * DOCUMENT ME!
+   *
+   * @param c DOCUMENT ME!
+   */
+  public void uninstallUI(JComponent c)
+  {
+    uninstallDefaults();
+    uninstallListeners();    
+    menuBar= null;
+  }
+
+  protected class ChangeHandler implements ChangeListener
+  {
+    public void stateChanged(ChangeEvent event)
+    {
+    }
+  }
+
+  protected class ContainerHandler implements ContainerListener
+  {
+    public void componentAdded(ContainerEvent e)
+    {
+    }
+
+    public void componentRemoved(ContainerEvent e)
+    {
+    }
+  }
+
+  protected class PropertyChangeHandler implements PropertyChangeListener
+  {
+    public void propertyChange(PropertyChangeEvent e)
+    {
+    }
+  }
+}
Index: javax/swing/plaf/basic/BasicMenuUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/Attic/BasicMenuUI.java,v
retrieving revision 1.1.2.1
diff -c -p -u -r1.1.2.1 BasicMenuUI.java
--- javax/swing/plaf/basic/BasicMenuUI.java	18 May 2004 14:31:21 -0000	1.1.2.1
+++ javax/swing/plaf/basic/BasicMenuUI.java	20 May 2004 15:04:44 -0000
@@ -51,6 +51,7 @@ import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import javax.swing.JComponent;
 import javax.swing.JMenu;
+import javax.swing.JMenuBar;
 import javax.swing.JMenuItem;
 import javax.swing.MenuElement;
 import javax.swing.MenuSelectionManager;
@@ -305,8 +306,14 @@ public class BasicMenuUI extends BasicMe
 
       // location of the popup menu is relative to the invoker
       if (subMenu.isTopLevelMenu())
-	y = subMenu.getHeight();
+        {
+	  JMenuBar mb = (JMenuBar) subMenu.getParent();
 
+	  // Take into account menu bar margin when calculating y coordinate
+	  // of the popup menu.
+	  y = subMenu.getHeight() - mb.getInsets().bottom
+	      + mb.getMargin().bottom;
+        }
       else
 	x = subMenu.getWidth();
 


More information about the Java-patches mailing list