-
Enhancement
-
Resolution: Not an Issue
-
P4
-
None
-
1.4.1
-
x86
-
windows_xp
Name: jk109818 Date: 06/10/2003
A DESCRIPTION OF THE REQUEST :
Currently, JSeparator does not support the MenuElement interface. JSeparator should be retrofitted to implement the interface so that operations performed on MenuElements do not need to treat them specially.
JUSTIFICATION :
Because JSeparator does not support the MenuElement interface, some operations treat them differently than "normal" menu elements. For example, when traversing a JMenu's elements using JMenu.getSubElements() and then MenuElement.getSubElements(), a null will appear whereever a JSeparator exists because it does not implement MenuElement.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JSeperator.getComponent: Return component from JSeperator's UI
JSeperator.getSubElements: Return zero length array
JSeperator.menuSelectionChanged: No-op
JSeperator.processKeyEvent: No-op
JSeperator.processMouseEvent: No-op
Any methods that deal with MenuElements should have any special processing attributed to JSeperator removed.
ACTUAL -
The MenuElement interface is not implemented by JSeperator.
---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
public class Sample {
public static void main(String[] args) {
JMenu menu = new JMenu("File");
menu.add(new JMenuItem("Open"));
menu.add(new JSeparator());
menu.add(new JMenuItem("Quit"));
System.out.println("Components:");
Component[] comps = menu.getMenuComponents();
for (int i=0; i<comps.length; i++)
System.out.println(comps[i].getClass().getName());
System.out.println("\nMenuElements:");
MenuElement[] elements = menu.getSubElements();
elements = elements[0].getSubElements();
for (int i=0; i<elements.length; i++) {
MenuElement e = elements[i];
System.out.println(e.getClass().getName());
}
System.out.println(
"\nThe JSeparator wasn't reported in the second query " +
"because JSeparator doesn't implement the MenuElement interface);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Menu's getMenuComponents() will report non-MenuElements that are contained within the menu.
(Review ID: 187430)
======================================================================