1 /*
2 * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
26 package javax.swing;
27
28 import java.awt.Component;
29 import java.awt.Font;
30 import java.awt.Image;
31 import java.awt.*;
32 import java.text.*;
33 import java.awt.geom.*;
34
35 import java.io.ObjectOutputStream;
36 import java.io.ObjectInputStream;
37 import java.io.IOException;
38
39 import javax.swing.plaf.LabelUI;
40 import javax.accessibility.*;
41 import javax.swing.text.*;
42 import javax.swing.text.html.*;
43 import javax.swing.plaf.basic.*;
44 import java.util.*;
45
46
47 /**
48 * A display area for a short text string or an image,
49 * or both.
50 * A label does not react to input events.
51 * As a result, it cannot get the keyboard focus.
52 * A label can, however, display a keyboard alternative
53 * as a convenience for a nearby component
54 * that has a keyboard alternative but can't display it.
55 * <p>
56 * A <code>JLabel</code> object can display
57 * either text, an image, or both.
58 * You can specify where in the label's display area
59 * the label's contents are aligned
60 * by setting the vertical and horizontal alignment.
61 * By default, labels are vertically centered
62 * in their display area.
63 * Text-only labels are leading edge aligned, by default;
64 * image-only labels are horizontally centered, by default.
65 * <p>
484 mnemonic = key;
485 firePropertyChange("displayedMnemonic", oldKey, mnemonic);
486
487 setDisplayedMnemonicIndex(
488 SwingUtilities.findDisplayedMnemonicIndex(getText(), mnemonic));
489
490 if (key != oldKey) {
491 revalidate();
492 repaint();
493 }
494 }
495
496
497 /**
498 * Specifies the displayedMnemonic as a char value.
499 *
500 * @param aChar a char specifying the mnemonic to display
501 * @see #setDisplayedMnemonic(int)
502 */
503 public void setDisplayedMnemonic(char aChar) {
504 int vk = (int) aChar;
505 if(vk >= 'a' && vk <='z')
506 vk -= ('a' - 'A');
507 setDisplayedMnemonic(vk);
508 }
509
510
511 /**
512 * Return the keycode that indicates a mnemonic key.
513 * This property is used when the label is part of a larger component.
514 * If the labelFor property of the label is not null, the label will
515 * call the requestFocus method of the component specified by the
516 * labelFor property when the mnemonic is activated.
517 *
518 * @return int value for the mnemonic key
519 *
520 * @see #getLabelFor
521 * @see #setLabelFor
522 */
523 public int getDisplayedMnemonic() {
524 return mnemonic;
525 }
526
527 /**
|
1 /*
2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
26 package javax.swing;
27
28 import java.awt.Component;
29 import java.awt.Font;
30 import java.awt.Image;
31 import java.awt.*;
32 import java.text.*;
33 import java.awt.geom.*;
34
35 import java.io.ObjectOutputStream;
36 import java.io.ObjectInputStream;
37 import java.io.IOException;
38
39 import javax.swing.plaf.LabelUI;
40 import javax.accessibility.*;
41 import javax.swing.text.*;
42 import javax.swing.text.html.*;
43 import javax.swing.plaf.basic.*;
44 import java.util.*;
45
46 import sun.awt.AWTAccessor;
47
48 /**
49 * A display area for a short text string or an image,
50 * or both.
51 * A label does not react to input events.
52 * As a result, it cannot get the keyboard focus.
53 * A label can, however, display a keyboard alternative
54 * as a convenience for a nearby component
55 * that has a keyboard alternative but can't display it.
56 * <p>
57 * A <code>JLabel</code> object can display
58 * either text, an image, or both.
59 * You can specify where in the label's display area
60 * the label's contents are aligned
61 * by setting the vertical and horizontal alignment.
62 * By default, labels are vertically centered
63 * in their display area.
64 * Text-only labels are leading edge aligned, by default;
65 * image-only labels are horizontally centered, by default.
66 * <p>
485 mnemonic = key;
486 firePropertyChange("displayedMnemonic", oldKey, mnemonic);
487
488 setDisplayedMnemonicIndex(
489 SwingUtilities.findDisplayedMnemonicIndex(getText(), mnemonic));
490
491 if (key != oldKey) {
492 revalidate();
493 repaint();
494 }
495 }
496
497
498 /**
499 * Specifies the displayedMnemonic as a char value.
500 *
501 * @param aChar a char specifying the mnemonic to display
502 * @see #setDisplayedMnemonic(int)
503 */
504 public void setDisplayedMnemonic(char aChar) {
505 int vk = AWTAccessor.getKeyEventAccessor().getExtendedKeyCodeForChar(aChar);
506 if (vk != java.awt.event.KeyEvent.VK_UNDEFINED) {
507 setDisplayedMnemonic(vk);
508 }
509 }
510
511
512 /**
513 * Return the keycode that indicates a mnemonic key.
514 * This property is used when the label is part of a larger component.
515 * If the labelFor property of the label is not null, the label will
516 * call the requestFocus method of the component specified by the
517 * labelFor property when the mnemonic is activated.
518 *
519 * @return int value for the mnemonic key
520 *
521 * @see #getLabelFor
522 * @see #setLabelFor
523 */
524 public int getDisplayedMnemonic() {
525 return mnemonic;
526 }
527
528 /**
|