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
|
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
------------------------------------------------------------
|