United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4138746 SetMnemonic should be case-sensitive
JDK-4138746 : SetMnemonic should be case-sensitive

Details
Type:
Bug
Submit Date:
1998-05-14
Status:
Resolved
Updated Date:
2000-10-11
Project Name:
JDK
Resolved Date:
2000-10-11
Component:
client-libs
OS:
solaris_2.6,windows_nt,generic
Sub-Component:
javax.swing
CPU:
x86,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.1.8,1.2.0,1.2.1
Fixed Versions:
1.4.0 (beta)

Related Reports
Duplicate:
Duplicate:

Sub Tasks

Description
In the entries: Mark Done, Mark ToDo, Mark Rejected,
setting mnemonics to D, T, and R, respectivly produce:
   Mark Done
        -
   Mark ToDo
        -
   Mark Rejected
     -
The specified mnemonic was upper case R, though, and that
would be the preferred character to underline. 

Name: krT82822			Date: 08/17/99


In the following example (and similarly with other components) you cannot specify the correct character to underline:

JLabel label = new JLabel ("Save As...");
label.setDisplayedMnemonic ('A');

The 'A' in 'As' should be underlined (that's the intention at least), but the 'a' in 'Save' is what gets underlined.

The problem (aside from the lack of an API to specify exactly what should be underlined) is in the javax.swing.plaf.basic.BasicGraphicUtils drawString method which underlines the first character (upper OR lowercase) that matches the mnemonic character.
(Review ID: 94042)
======================================================================

                                    

Comments
SUGGESTED FIX

A new property "displayedMnemonicIndex" is introduced
in classes AbstractButton and JLabel. It tells which
character to underline. So for example to underline
the capital 'A' in 'Save As', one should call:

    setMnemonic('A');
    setDisplayedMnemonicIndex(5);

A new method, BasicGraphicsUtils.drawStringUnderlineChar(),
is also needed. It takes an int parameter telling which
character to underline. Unfortunately we can't call this
method drawString(), because such a method with the same
signature already exists.

New methods added:
------------------
AbstractButton.setDisplayedMnemonicIndex();
AbstractButton.getDisplayedMnemonicIndex();
JLabel.setDisplayedMnemonicIndex();
JLabel.getDisplayedMnemonicIndex();
BasicGraphicsUtils.drawStringUnderlineChar();

Files modified:
---------------
AbstractButton.java
JLabel.java
BasicLabelUI.java
BasicButtonUI.java
BasicGraphicsUtils.java
MetalButtonUI.java
MetalLabelUI.java

The diffs will be attached, as there are too many to list them here.
Please see attached fix.zip file.

###@###.### 2000-07-25
------------------------------------------------------------
                                     
2000-07-25
EVALUATION

Agreed. When looking for the character to underline it should first do a case sensitive search, then case insensitive.
sky 1998-05-29

The problem is that mnemonic character is underlined by the
BasicGraphicsUtils.drawString() method, which performs case-
insensitive search. Since this is a public method, we can't
simply change it to performs case-sensitive search.

###@###.### 2000-07-25

As this is an often requested feature, the following will be added to JLabel and AbstractButton:
    /**
     * Provides a hint to the look and feel as to which character in the
     * text should be decorated to represent the mnemonic. Not all look and
     * feels may support this. A value of -1 indicates either there is no
     * mnemonic, the mnemonic character is not contained in the string, or
     * the developer does not wish the mnemonic to be displayed.
     * <p>
     * The value of this is updated as the properties relating to the
     * mnemonic change (such as the mnemonic itself, the text...).
     * You should only ever have to call this if
     * you do not wish the default character to be underlined. For example, if
     * the text was 'Save As', with a mnemonic of 'a', and you wanted the 'A'
     * to be decorated, as 'Save <u>A</u>s', you would have to invoke
     * <code>setDisplayedMnemonicIndex(5)</code> after invoking
     * <code>setMnemonic(KeyEvent.VK_A)</code>.
     *
     * @since 1.4
     * @param index Index into the String to underline
     * @exception IllegalArgumentException will be thrown if <code>index</code>
     *            is >= length of the text, or < -1
     *
     * @beaninfo
     *        bound: true
     *    attribute: visualUpdate true
     *  description: the index into the String to draw the keyboard character
     *               mnemonic at
     */
    public void setDisplayedMnemonicIndex(int index)
                                          throws IllegalArgumentException;


    /**
     * Returns the character, as an index, that the look and feel should
     * provide decoration for as representing the mnemonic character.
     *
     * @since 1.4
     * @return index representing mnemonic character
     * @see #setDisplayedMnemonicIndex
     */
    public int getDisplayedMnemonicIndex();

  Add the following to javax.swing.plaf.basic.BasicGraphicsUtils:

    /**
     * Draw a string with the graphics <code>g</code> at location
     * (<code>x</code>, <code>y</code>)
     * just like <code>g.drawString</code> would.
     * The character at index <code>underlinedIndex</code>
     * in text will be underlined. If <code>index</code> is beyond the
     * bounds of <code>text</code> (including < 0), nothing will be
     * underlined.
     *
     * @param g Graphics to draw with
     * @param text String to draw
     * @param underlinedIndex Index of character in text to underline
     * @param x x coordinate to draw at
     * @param y y coordinate to draw at
     * @since 1.4
     */
    public static void drawStringUnderlineCharAt(Graphics g, String text,
                           int underlinedIndex, int x, int y);

scott.violet@eng 2000-08-09
                                     
2000-08-09
WORK AROUND



Name: krT82822			Date: 08/17/99


The only work around that I know of is to pick your text and mnemonic character carefully.
(Review ID: 94042)
======================================================================
                                     
2004-08-24
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
merlin-beta

FIXED IN:
merlin-beta

INTEGRATED IN:
merlin-beta


                                     
2004-08-24



Hardware and Software, Engineered to Work Together