5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javax.swing;
27
28 import java.awt.Component;
29 import java.awt.Dimension;
30 import java.awt.Graphics;
31 import java.awt.Insets;
32 import java.awt.Point;
33 import java.awt.Rectangle;
34 import java.awt.event.*;
35 import java.beans.Transient;
36 import java.util.Vector;
37 import java.util.Enumeration;
38
39 import java.io.Serializable;
40 import java.io.ObjectOutputStream;
41 import java.io.ObjectInputStream;
42 import java.io.IOException;
43
44 import javax.swing.event.*;
45 import javax.swing.border.Border;
46 import javax.swing.plaf.*;
47 import javax.accessibility.*;
48
49 /**
50 * An implementation of a menu bar. You add <code>JMenu</code> objects to the
51 * menu bar to construct a menu. When the user selects a <code>JMenu</code>
52 * object, its associated <code>JPopupMenu</code> is displayed, allowing the
53 * user to select one of the <code>JMenuItems</code> on it.
54 * <p>
55 * For information and examples of using menu bars see
56 * <a
57 href="http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html">How to Use Menus</a>,
58 * a section in <em>The Java Tutorial.</em>
59 * <p>
60 * <strong>Warning:</strong> Swing is not thread safe. For more
61 * information see <a
62 * href="package-summary.html#threading">Swing's Threading
63 * Policy</a>.
64 * <p>
65 * <strong>Warning:</strong>
66 * Serialized objects of this class will not be compatible with
67 * future Swing releases. The current serialization support is
68 * appropriate for short term storage or RMI between applications running
69 * the same version of Swing. As of 1.4, support for long term storage
70 * of all JavaBeans™
71 * has been added to the <code>java.beans</code> package.
72 * Please see {@link java.beans.XMLEncoder}.
73 * <p>
74 * <strong>Warning:</strong>
75 * By default, pressing the Tab key does not transfer focus from a <code>
76 * JMenuBar</code> which is added to a container together with other Swing
77 * components, because the <code>focusTraversalKeysEnabled</code> property
78 * of <code>JMenuBar</code> is set to <code>false</code>. To resolve this,
79 * you should call the <code>JMenuBar.setFocusTraversalKeysEnabled(true)</code>
80 * method.
81 * @beaninfo
82 * attribute: isContainer true
83 * description: A container for holding and displaying menus.
84 *
85 * @author Georges Saab
86 * @author David Karlton
87 * @author Arnaud Weber
88 * @see JMenu
89 * @see JPopupMenu
90 * @see JMenuItem
91 * @since 1.2
92 */
93 @SuppressWarnings("serial")
94 public class JMenuBar extends JComponent implements Accessible,MenuElement
95 {
96 /**
97 * @see #getUIClassID
98 * @see #readObject
99 */
100 private static final String uiClassID = "MenuBarUI";
101
102 /*
103 * Model for the selected subcontrol.
104 */
105 private transient SingleSelectionModel selectionModel;
106
107 private boolean paintBorder = true;
108 private Insets margin = null;
109
110 /* diagnostic aids -- should be false for production builds. */
111 private static final boolean TRACE = false; // trace creates and disposes
112 private static final boolean VERBOSE = false; // show reuse hits/misses
120 setFocusTraversalKeysEnabled(false);
121 setSelectionModel(new DefaultSingleSelectionModel());
122 updateUI();
123 }
124
125 /**
126 * Returns the menubar's current UI.
127 *
128 * @return a {@code MenuBarUI} which is the menubar's current L&F object
129 * @see #setUI
130 */
131 public MenuBarUI getUI() {
132 return (MenuBarUI)ui;
133 }
134
135 /**
136 * Sets the L&F object that renders this component.
137 *
138 * @param ui the new MenuBarUI L&F object
139 * @see UIDefaults#getUI
140 * @beaninfo
141 * bound: true
142 * hidden: true
143 * attribute: visualUpdate true
144 * description: The UI object that implements the Component's LookAndFeel.
145 */
146 public void setUI(MenuBarUI ui) {
147 super.setUI(ui);
148 }
149
150 /**
151 * Resets the UI property with a value from the current look and feel.
152 *
153 * @see JComponent#updateUI
154 */
155 public void updateUI() {
156 setUI((MenuBarUI)UIManager.getUI(this));
157 }
158
159
160 /**
161 * Returns the name of the L&F class that renders this component.
162 *
163 * @return the string "MenuBarUI"
164 * @see JComponent#getUIClassID
165 * @see UIDefaults#getUI
166 */
167 public String getUIClassID() {
168 return uiClassID;
169 }
170
171
172 /**
173 * Returns the model object that handles single selections.
174 *
175 * @return the <code>SingleSelectionModel</code> property
176 * @see SingleSelectionModel
177 */
178 public SingleSelectionModel getSelectionModel() {
179 return selectionModel;
180 }
181
182 /**
183 * Sets the model object to handle single selections.
184 *
185 * @param model the <code>SingleSelectionModel</code> to use
186 * @see SingleSelectionModel
187 * @beaninfo
188 * bound: true
189 * description: The selection model, recording which child is selected.
190 */
191 public void setSelectionModel(SingleSelectionModel model) {
192 SingleSelectionModel oldValue = selectionModel;
193 this.selectionModel = model;
194 firePropertyChange("selectionModel", oldValue, selectionModel);
195 }
196
197
198 /**
199 * Appends the specified menu to the end of the menu bar.
200 *
201 * @param c the <code>JMenu</code> component to add
202 * @return the menu component
203 */
204 public JMenu add(JMenu c) {
205 super.add(c);
206 return c;
207 }
208
209 /**
210 * Returns the menu at the specified position in the menu bar.
211 *
212 * @param index an integer giving the position in the menu bar, where
213 * 0 is the first position
214 * @return the <code>JMenu</code> at that position, or <code>null</code> if
215 * if there is no <code>JMenu</code> at that position (ie. if
216 * it is a <code>JMenuItem</code>)
217 */
218 public JMenu getMenu(int index) {
219 Component c = getComponentAtIndex(index);
220 if (c instanceof JMenu)
221 return (JMenu) c;
222 return null;
223 }
224
225 /**
226 * Returns the number of items in the menu bar.
227 *
228 * @return the number of items in the menu bar
229 */
230 public int getMenuCount() {
231 return getComponentCount();
232 }
233
234 /**
235 * Sets the help menu that appears when the user selects the
236 * "help" option in the menu bar. This method is not yet implemented
237 * and will throw an exception.
238 *
239 * @param menu the JMenu that delivers help to the user
240 */
241 public void setHelpMenu(JMenu menu) {
242 throw new Error("setHelpMenu() not yet implemented.");
243 }
244
245 /**
246 * Gets the help menu for the menu bar. This method is not yet
247 * implemented and will throw an exception.
248 *
249 * @return the <code>JMenu</code> that delivers help to the user
287 return -1;
288 }
289
290 /**
291 * Sets the currently selected component, producing a
292 * a change to the selection model.
293 *
294 * @param sel the <code>Component</code> to select
295 */
296 public void setSelected(Component sel) {
297 SingleSelectionModel model = getSelectionModel();
298 int index = getComponentIndex(sel);
299 model.setSelectedIndex(index);
300 }
301
302 /**
303 * Returns true if the menu bar currently has a component selected.
304 *
305 * @return true if a selection has been made, else false
306 */
307 public boolean isSelected() {
308 return selectionModel.isSelected();
309 }
310
311 /**
312 * Returns true if the menu bars border should be painted.
313 *
314 * @return true if the border should be painted, else false
315 */
316 public boolean isBorderPainted() {
317 return paintBorder;
318 }
319
320 /**
321 * Sets whether the border should be painted.
322 *
323 * @param b if true and border property is not <code>null</code>,
324 * the border is painted.
325 * @see #isBorderPainted
326 * @beaninfo
327 * bound: true
328 * attribute: visualUpdate true
329 * description: Whether the border should be painted.
330 */
331 public void setBorderPainted(boolean b) {
332 boolean oldValue = paintBorder;
333 paintBorder = b;
334 firePropertyChange("borderPainted", oldValue, paintBorder);
335 if (b != oldValue) {
336 revalidate();
337 repaint();
338 }
339 }
340
341 /**
342 * Paints the menubar's border if <code>BorderPainted</code>
343 * property is true.
344 *
345 * @param g the <code>Graphics</code> context to use for painting
346 * @see JComponent#paint
347 * @see JComponent#setBorder
348 */
349 protected void paintBorder(Graphics g) {
350 if (isBorderPainted()) {
351 super.paintBorder(g);
352 }
353 }
354
355 /**
356 * Sets the margin between the menubar's border and
357 * its menus. Setting to <code>null</code> will cause the menubar to
358 * use the default margins.
359 *
360 * @param m an Insets object containing the margin values
361 * @see Insets
362 * @beaninfo
363 * bound: true
364 * attribute: visualUpdate true
365 * description: The space between the menubar's border and its contents
366 */
367 public void setMargin(Insets m) {
368 Insets old = margin;
369 this.margin = m;
370 firePropertyChange("margin", old, m);
371 if (old == null || !old.equals(m)) {
372 revalidate();
373 repaint();
374 }
375 }
376
377 /**
378 * Returns the margin between the menubar's border and
379 * its menus. If there is no previous margin, it will create
380 * a default margin with zero size.
381 *
382 * @return an <code>Insets</code> object containing the margin values
383 * @see Insets
384 */
385 public Insets getMargin() {
386 if(margin == null) {
406 */
407 public void processKeyEvent(KeyEvent e,MenuElement path[],MenuSelectionManager manager) {
408 }
409
410 /**
411 * Implemented to be a <code>MenuElement</code> -- does nothing.
412 *
413 * @see #getSubElements
414 */
415 public void menuSelectionChanged(boolean isIncluded) {
416 }
417
418 /**
419 * Implemented to be a <code>MenuElement</code> -- returns the
420 * menus in this menu bar.
421 * This is the reason for implementing the <code>MenuElement</code>
422 * interface -- so that the menu bar can be treated the same as
423 * other menu elements.
424 * @return an array of menu items in the menu bar.
425 */
426 public MenuElement[] getSubElements() {
427 MenuElement result[];
428 Vector<MenuElement> tmp = new Vector<MenuElement>();
429 int c = getComponentCount();
430 int i;
431 Component m;
432
433 for(i=0 ; i < c ; i++) {
434 m = getComponent(i);
435 if(m instanceof MenuElement)
436 tmp.addElement((MenuElement) m);
437 }
438
439 result = new MenuElement[tmp.size()];
440 for(i=0,c=tmp.size() ; i < c ; i++)
441 result[i] = tmp.elementAt(i);
442 return result;
443 }
444
445 /**
470 margin.toString() : "");
471
472 return super.paramString() +
473 ",margin=" + marginString +
474 ",paintBorder=" + paintBorderString;
475 }
476
477 /////////////////
478 // Accessibility support
479 ////////////////
480
481 /**
482 * Gets the AccessibleContext associated with this JMenuBar.
483 * For JMenuBars, the AccessibleContext takes the form of an
484 * AccessibleJMenuBar.
485 * A new AccessibleJMenuBar instance is created if necessary.
486 *
487 * @return an AccessibleJMenuBar that serves as the
488 * AccessibleContext of this JMenuBar
489 */
490 public AccessibleContext getAccessibleContext() {
491 if (accessibleContext == null) {
492 accessibleContext = new AccessibleJMenuBar();
493 }
494 return accessibleContext;
495 }
496
497 /**
498 * This class implements accessibility support for the
499 * <code>JMenuBar</code> class. It provides an implementation of the
500 * Java Accessibility API appropriate to menu bar user-interface
501 * elements.
502 * <p>
503 * <strong>Warning:</strong>
504 * Serialized objects of this class will not be compatible with
505 * future Swing releases. The current serialization support is
506 * appropriate for short term storage or RMI between applications running
507 * the same version of Swing. As of 1.4, support for long term storage
508 * of all JavaBeans™
509 * has been added to the <code>java.beans</code> package.
|
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package javax.swing;
26
27 import java.awt.Component;
28 import java.awt.Graphics;
29 import java.awt.Insets;
30 import java.awt.event.*;
31 import java.beans.JavaBean;
32 import java.beans.BeanProperty;
33 import java.beans.Transient;
34 import java.util.Vector;
35
36 import java.io.Serializable;
37 import java.io.ObjectOutputStream;
38 import java.io.ObjectInputStream;
39 import java.io.IOException;
40
41 import javax.swing.plaf.*;
42 import javax.accessibility.*;
43
44 /**
45 * An implementation of a menu bar. You add <code>JMenu</code> objects to the
46 * menu bar to construct a menu. When the user selects a <code>JMenu</code>
47 * object, its associated <code>JPopupMenu</code> is displayed, allowing the
48 * user to select one of the <code>JMenuItems</code> on it.
49 * <p>
50 * For information and examples of using menu bars see
51 * <a
52 href="http://docs.oracle.com/javase/tutorial/uiswing/components/menu.html">How to Use Menus</a>,
53 * a section in <em>The Java Tutorial.</em>
54 * <p>
55 * <strong>Warning:</strong> Swing is not thread safe. For more
56 * information see <a
57 * href="package-summary.html#threading">Swing's Threading
58 * Policy</a>.
59 * <p>
60 * <strong>Warning:</strong>
61 * Serialized objects of this class will not be compatible with
62 * future Swing releases. The current serialization support is
63 * appropriate for short term storage or RMI between applications running
64 * the same version of Swing. As of 1.4, support for long term storage
65 * of all JavaBeans™
66 * has been added to the <code>java.beans</code> package.
67 * Please see {@link java.beans.XMLEncoder}.
68 * <p>
69 * <strong>Warning:</strong>
70 * By default, pressing the Tab key does not transfer focus from a <code>
71 * JMenuBar</code> which is added to a container together with other Swing
72 * components, because the <code>focusTraversalKeysEnabled</code> property
73 * of <code>JMenuBar</code> is set to <code>false</code>. To resolve this,
74 * you should call the <code>JMenuBar.setFocusTraversalKeysEnabled(true)</code>
75 * method.
76 *
77 * @author Georges Saab
78 * @author David Karlton
79 * @author Arnaud Weber
80 * @see JMenu
81 * @see JPopupMenu
82 * @see JMenuItem
83 * @since 1.2
84 */
85 @JavaBean(defaultProperty = "UI", description = "A container for holding and displaying menus.")
86 @SwingContainer
87 @SuppressWarnings("serial")
88 public class JMenuBar extends JComponent implements Accessible,MenuElement
89 {
90 /**
91 * @see #getUIClassID
92 * @see #readObject
93 */
94 private static final String uiClassID = "MenuBarUI";
95
96 /*
97 * Model for the selected subcontrol.
98 */
99 private transient SingleSelectionModel selectionModel;
100
101 private boolean paintBorder = true;
102 private Insets margin = null;
103
104 /* diagnostic aids -- should be false for production builds. */
105 private static final boolean TRACE = false; // trace creates and disposes
106 private static final boolean VERBOSE = false; // show reuse hits/misses
114 setFocusTraversalKeysEnabled(false);
115 setSelectionModel(new DefaultSingleSelectionModel());
116 updateUI();
117 }
118
119 /**
120 * Returns the menubar's current UI.
121 *
122 * @return a {@code MenuBarUI} which is the menubar's current L&F object
123 * @see #setUI
124 */
125 public MenuBarUI getUI() {
126 return (MenuBarUI)ui;
127 }
128
129 /**
130 * Sets the L&F object that renders this component.
131 *
132 * @param ui the new MenuBarUI L&F object
133 * @see UIDefaults#getUI
134 */
135 @BeanProperty(hidden = true, visualUpdate = true, description
136 = "The UI object that implements the Component's LookAndFeel.")
137 public void setUI(MenuBarUI ui) {
138 super.setUI(ui);
139 }
140
141 /**
142 * Resets the UI property with a value from the current look and feel.
143 *
144 * @see JComponent#updateUI
145 */
146 public void updateUI() {
147 setUI((MenuBarUI)UIManager.getUI(this));
148 }
149
150
151 /**
152 * Returns the name of the L&F class that renders this component.
153 *
154 * @return the string "MenuBarUI"
155 * @see JComponent#getUIClassID
156 * @see UIDefaults#getUI
157 */
158 @BeanProperty(bound = false)
159 public String getUIClassID() {
160 return uiClassID;
161 }
162
163
164 /**
165 * Returns the model object that handles single selections.
166 *
167 * @return the <code>SingleSelectionModel</code> property
168 * @see SingleSelectionModel
169 */
170 public SingleSelectionModel getSelectionModel() {
171 return selectionModel;
172 }
173
174 /**
175 * Sets the model object to handle single selections.
176 *
177 * @param model the <code>SingleSelectionModel</code> to use
178 * @see SingleSelectionModel
179 */
180 @BeanProperty(description = "The selection model, recording which child is selected.")
181 public void setSelectionModel(SingleSelectionModel model) {
182 SingleSelectionModel oldValue = selectionModel;
183 this.selectionModel = model;
184 firePropertyChange("selectionModel", oldValue, selectionModel);
185 }
186
187
188 /**
189 * Appends the specified menu to the end of the menu bar.
190 *
191 * @param c the <code>JMenu</code> component to add
192 * @return the menu component
193 */
194 public JMenu add(JMenu c) {
195 super.add(c);
196 return c;
197 }
198
199 /**
200 * Returns the menu at the specified position in the menu bar.
201 *
202 * @param index an integer giving the position in the menu bar, where
203 * 0 is the first position
204 * @return the <code>JMenu</code> at that position, or <code>null</code> if
205 * if there is no <code>JMenu</code> at that position (ie. if
206 * it is a <code>JMenuItem</code>)
207 */
208 public JMenu getMenu(int index) {
209 Component c = getComponentAtIndex(index);
210 if (c instanceof JMenu)
211 return (JMenu) c;
212 return null;
213 }
214
215 /**
216 * Returns the number of items in the menu bar.
217 *
218 * @return the number of items in the menu bar
219 */
220 @BeanProperty(bound = false)
221 public int getMenuCount() {
222 return getComponentCount();
223 }
224
225 /**
226 * Sets the help menu that appears when the user selects the
227 * "help" option in the menu bar. This method is not yet implemented
228 * and will throw an exception.
229 *
230 * @param menu the JMenu that delivers help to the user
231 */
232 public void setHelpMenu(JMenu menu) {
233 throw new Error("setHelpMenu() not yet implemented.");
234 }
235
236 /**
237 * Gets the help menu for the menu bar. This method is not yet
238 * implemented and will throw an exception.
239 *
240 * @return the <code>JMenu</code> that delivers help to the user
278 return -1;
279 }
280
281 /**
282 * Sets the currently selected component, producing a
283 * a change to the selection model.
284 *
285 * @param sel the <code>Component</code> to select
286 */
287 public void setSelected(Component sel) {
288 SingleSelectionModel model = getSelectionModel();
289 int index = getComponentIndex(sel);
290 model.setSelectedIndex(index);
291 }
292
293 /**
294 * Returns true if the menu bar currently has a component selected.
295 *
296 * @return true if a selection has been made, else false
297 */
298 @BeanProperty(bound = false)
299 public boolean isSelected() {
300 return selectionModel.isSelected();
301 }
302
303 /**
304 * Returns true if the menu bars border should be painted.
305 *
306 * @return true if the border should be painted, else false
307 */
308 public boolean isBorderPainted() {
309 return paintBorder;
310 }
311
312 /**
313 * Sets whether the border should be painted.
314 *
315 * @param b if true and border property is not <code>null</code>,
316 * the border is painted.
317 * @see #isBorderPainted
318 */
319 @BeanProperty(visualUpdate = true, description
320 = "Whether the border should be painted.")
321 public void setBorderPainted(boolean b) {
322 boolean oldValue = paintBorder;
323 paintBorder = b;
324 firePropertyChange("borderPainted", oldValue, paintBorder);
325 if (b != oldValue) {
326 revalidate();
327 repaint();
328 }
329 }
330
331 /**
332 * Paints the menubar's border if <code>BorderPainted</code>
333 * property is true.
334 *
335 * @param g the <code>Graphics</code> context to use for painting
336 * @see JComponent#paint
337 * @see JComponent#setBorder
338 */
339 protected void paintBorder(Graphics g) {
340 if (isBorderPainted()) {
341 super.paintBorder(g);
342 }
343 }
344
345 /**
346 * Sets the margin between the menubar's border and
347 * its menus. Setting to <code>null</code> will cause the menubar to
348 * use the default margins.
349 *
350 * @param m an Insets object containing the margin values
351 * @see Insets
352 */
353 @BeanProperty(visualUpdate = true, description
354 = "The space between the menubar's border and its contents")
355 public void setMargin(Insets m) {
356 Insets old = margin;
357 this.margin = m;
358 firePropertyChange("margin", old, m);
359 if (old == null || !old.equals(m)) {
360 revalidate();
361 repaint();
362 }
363 }
364
365 /**
366 * Returns the margin between the menubar's border and
367 * its menus. If there is no previous margin, it will create
368 * a default margin with zero size.
369 *
370 * @return an <code>Insets</code> object containing the margin values
371 * @see Insets
372 */
373 public Insets getMargin() {
374 if(margin == null) {
394 */
395 public void processKeyEvent(KeyEvent e,MenuElement path[],MenuSelectionManager manager) {
396 }
397
398 /**
399 * Implemented to be a <code>MenuElement</code> -- does nothing.
400 *
401 * @see #getSubElements
402 */
403 public void menuSelectionChanged(boolean isIncluded) {
404 }
405
406 /**
407 * Implemented to be a <code>MenuElement</code> -- returns the
408 * menus in this menu bar.
409 * This is the reason for implementing the <code>MenuElement</code>
410 * interface -- so that the menu bar can be treated the same as
411 * other menu elements.
412 * @return an array of menu items in the menu bar.
413 */
414 @BeanProperty(bound = false)
415 public MenuElement[] getSubElements() {
416 MenuElement result[];
417 Vector<MenuElement> tmp = new Vector<MenuElement>();
418 int c = getComponentCount();
419 int i;
420 Component m;
421
422 for(i=0 ; i < c ; i++) {
423 m = getComponent(i);
424 if(m instanceof MenuElement)
425 tmp.addElement((MenuElement) m);
426 }
427
428 result = new MenuElement[tmp.size()];
429 for(i=0,c=tmp.size() ; i < c ; i++)
430 result[i] = tmp.elementAt(i);
431 return result;
432 }
433
434 /**
459 margin.toString() : "");
460
461 return super.paramString() +
462 ",margin=" + marginString +
463 ",paintBorder=" + paintBorderString;
464 }
465
466 /////////////////
467 // Accessibility support
468 ////////////////
469
470 /**
471 * Gets the AccessibleContext associated with this JMenuBar.
472 * For JMenuBars, the AccessibleContext takes the form of an
473 * AccessibleJMenuBar.
474 * A new AccessibleJMenuBar instance is created if necessary.
475 *
476 * @return an AccessibleJMenuBar that serves as the
477 * AccessibleContext of this JMenuBar
478 */
479 @BeanProperty(bound = false)
480 public AccessibleContext getAccessibleContext() {
481 if (accessibleContext == null) {
482 accessibleContext = new AccessibleJMenuBar();
483 }
484 return accessibleContext;
485 }
486
487 /**
488 * This class implements accessibility support for the
489 * <code>JMenuBar</code> class. It provides an implementation of the
490 * Java Accessibility API appropriate to menu bar user-interface
491 * elements.
492 * <p>
493 * <strong>Warning:</strong>
494 * Serialized objects of this class will not be compatible with
495 * future Swing releases. The current serialization support is
496 * appropriate for short term storage or RMI between applications running
497 * the same version of Swing. As of 1.4, support for long term storage
498 * of all JavaBeans™
499 * has been added to the <code>java.beans</code> package.
|