Methods Summary |
---|
public javax.swing.JMenu | add(javax.swing.JMenu c)Appends the specified menu to the end of the menu bar.
super.add(c);
return c;
|
public void | addNotify()Overrides JComponent.addNotify to register this
menu bar with the current keyboard manager.
super.addNotify();
KeyboardManager.getCurrentManager().registerMenuBar(this);
|
public javax.accessibility.AccessibleContext | getAccessibleContext()Gets the AccessibleContext associated with this JMenuBar.
For JMenuBars, the AccessibleContext takes the form of an
AccessibleJMenuBar.
A new AccessibleJMenuBar instance is created if necessary.
if (accessibleContext == null) {
accessibleContext = new AccessibleJMenuBar();
}
return accessibleContext;
|
public java.awt.Component | getComponent()Implemented to be a MenuElement . Returns this object.
return this;
|
public java.awt.Component | getComponentAtIndex(int i)Returns the component at the specified index.
return getComponent(i);
|
public int | getComponentIndex(java.awt.Component c)Returns the index of the specified component.
int ncomponents = this.getComponentCount();
Component[] component = this.getComponents();
for (int i = 0 ; i < ncomponents ; i++) {
Component comp = component[i];
if (comp == c)
return i;
}
return -1;
|
public javax.swing.JMenu | getHelpMenu()Gets the help menu for the menu bar. This method is not yet
implemented and will throw an exception.
throw new Error("getHelpMenu() not yet implemented.");
|
public java.awt.Insets | getMargin()Returns the margin between the menubar's border and
its menus. If there is no previous margin, it will create
a default margin with zero size.
if(margin == null) {
return new Insets(0,0,0,0);
} else {
return margin;
}
|
public javax.swing.JMenu | getMenu(int index)Returns the menu at the specified position in the menu bar.
Component c = getComponentAtIndex(index);
if (c instanceof JMenu)
return (JMenu) c;
return null;
|
public int | getMenuCount()Returns the number of items in the menu bar.
return getComponentCount();
|
public javax.swing.SingleSelectionModel | getSelectionModel()Returns the model object that handles single selections.
return selectionModel;
|
public javax.swing.MenuElement[] | getSubElements()Implemented to be a MenuElement -- returns the
menus in this menu bar.
This is the reason for implementing the MenuElement
interface -- so that the menu bar can be treated the same as
other menu elements.
MenuElement result[];
Vector tmp = new Vector();
int c = getComponentCount();
int i;
Component m;
for(i=0 ; i < c ; i++) {
m = getComponent(i);
if(m instanceof MenuElement)
tmp.addElement(m);
}
result = new MenuElement[tmp.size()];
for(i=0,c=tmp.size() ; i < c ; i++)
result[i] = (MenuElement) tmp.elementAt(i);
return result;
|
public javax.swing.plaf.MenuBarUI | getUI()Returns the menubar's current UI.
return (MenuBarUI)ui;
|
public java.lang.String | getUIClassID()Returns the name of the L&F class that renders this component.
return uiClassID;
|
public boolean | isBorderPainted()Returns true if the menu bars border should be painted.
return paintBorder;
|
public boolean | isSelected()Returns true if the menu bar currently has a component selected.
return selectionModel.isSelected();
|
public void | menuSelectionChanged(boolean isIncluded)Implemented to be a MenuElement -- does nothing.
|
protected void | paintBorder(java.awt.Graphics g)Paints the menubar's border if BorderPainted
property is true.
if (isBorderPainted()) {
super.paintBorder(g);
}
|
protected java.lang.String | paramString()Returns a string representation of this JMenuBar .
This method
is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null .
String paintBorderString = (paintBorder ?
"true" : "false");
String marginString = (margin != null ?
margin.toString() : "");
return super.paramString() +
",margin=" + marginString +
",paintBorder=" + paintBorderString;
|
static boolean | processBindingForKeyStrokeRecursive(javax.swing.MenuElement elem, javax.swing.KeyStroke ks, java.awt.event.KeyEvent e, int condition, boolean pressed)
if (elem == null) {
return false;
}
Component c = elem.getComponent();
if (c != null && c instanceof JComponent &&
((JComponent)c).processKeyBinding(ks, e, condition, pressed)) {
return true;
}
MenuElement[] subElements = elem.getSubElements();
for(int i=0; i<subElements.length; i++) {
if (processBindingForKeyStrokeRecursive(subElements[i], ks, e,
condition, pressed)) {
return true;
// We don't, pass along to children JMenu's
}
}
return false;
|
protected boolean | processKeyBinding(javax.swing.KeyStroke ks, java.awt.event.KeyEvent e, int condition, boolean pressed)Subclassed to check all the child menus.
// See if we have a local binding.
boolean retValue = super.processKeyBinding(ks, e, condition, pressed);
if (!retValue) {
MenuElement[] subElements = getSubElements();
for (int i=0; i<subElements.length; i++) {
if (processBindingForKeyStrokeRecursive(
subElements[i], ks, e, condition, pressed)) {
return true;
}
}
}
return retValue;
|
public void | processKeyEvent(java.awt.event.KeyEvent e, javax.swing.MenuElement[] path, javax.swing.MenuSelectionManager manager)Implemented to be a MenuElement -- does nothing.
|
public void | processMouseEvent(java.awt.event.MouseEvent event, javax.swing.MenuElement[] path, javax.swing.MenuSelectionManager manager)Implemented to be a MenuElement -- does nothing.
|
private void | readObject(java.io.ObjectInputStream s)See JComponent.readObject() for information about serialization
in Swing.
s.defaultReadObject();
Object[] kvData = (Object[])(s.readObject());
for(int i = 0; i < kvData.length; i += 2) {
if (kvData[i] == null) {
break;
}
else if (kvData[i].equals("selectionModel")) {
selectionModel = (SingleSelectionModel)kvData[i + 1];
}
}
|
public void | removeNotify()Overrides JComponent.removeNotify to unregister this
menu bar with the current keyboard manager.
super.removeNotify();
KeyboardManager.getCurrentManager().unregisterMenuBar(this);
|
public void | setBorderPainted(boolean b)Sets whether the border should be painted.
boolean oldValue = paintBorder;
paintBorder = b;
firePropertyChange("borderPainted", oldValue, paintBorder);
if (b != oldValue) {
revalidate();
repaint();
}
|
public void | setHelpMenu(javax.swing.JMenu menu)Sets the help menu that appears when the user selects the
"help" option in the menu bar. This method is not yet implemented
and will throw an exception.
throw new Error("setHelpMenu() not yet implemented.");
|
public void | setMargin(java.awt.Insets m)Sets the margin between the menubar's border and
its menus. Setting to null will cause the menubar to
use the default margins.
Insets old = margin;
this.margin = m;
firePropertyChange("margin", old, m);
if (old == null || !old.equals(m)) {
revalidate();
repaint();
}
|
public void | setSelected(java.awt.Component sel)Sets the currently selected component, producing a
a change to the selection model.
SingleSelectionModel model = getSelectionModel();
int index = getComponentIndex(sel);
model.setSelectedIndex(index);
|
public void | setSelectionModel(javax.swing.SingleSelectionModel model)Sets the model object to handle single selections.
SingleSelectionModel oldValue = selectionModel;
this.selectionModel = model;
firePropertyChange("selectionModel", oldValue, selectionModel);
|
public void | setUI(javax.swing.plaf.MenuBarUI ui)Sets the L&F object that renders this component.
super.setUI(ui);
|
public void | updateUI()Resets the UI property with a value from the current look and feel.
setUI((MenuBarUI)UIManager.getUI(this));
|
private void | writeObject(java.io.ObjectOutputStream s)
s.defaultWriteObject();
if (getUIClassID().equals(uiClassID)) {
byte count = JComponent.getWriteObjCounter(this);
JComponent.setWriteObjCounter(this, --count);
if (count == 0 && ui != null) {
ui.installUI(this);
}
}
Object[] kvData = new Object[4];
int n = 0;
if (selectionModel instanceof Serializable) {
kvData[n++] = "selectionModel";
kvData[n++] = selectionModel;
}
s.writeObject(kvData);
|