-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
7
-
x86
-
linux
Run the following program in Ocean L&F (I use JDK 7 b04 on FC 6 Linux):
---%<---
import javax.swing.*;
import java.awt.event.*;
public class HtmlMnemonic extends JFrame {
private HtmlMnemonic() {
super("HtmlMnemonic");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JMenuBar mb = new JMenuBar();
setJMenuBar(mb);
JMenu m = new JMenu();
mb.add(m);
m.setText("Menu");
m.setMnemonic('M');
JMenuItem mi = new JMenuItem();
m.add(mi);
mi.setText("<html>Foo");
mi.setMnemonic('F');
//mi.setDisplayedMnemonicIndex(0);
//mi.setDisplayedMnemonicIndex(6);
mi.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("menu item selected");
}
});
pack();
}
public static void main(String[] args) {
new HtmlMnemonic().setVisible(true);
}
}
---%<---
Press Alt-M. The menu "_M_enu" will be posted. Press F. "menu item selected" will be printed. But the menu item "Foo" does not display the mnemonic, as in "_F_oo", in contrast to non-HTML labels.
Uncommenting either of the calls to setDisplayedMnemonicIndex does not help. The index 6 ought to correspond to the location of 'F' in the HTML string, while the index 0 ought to correspond to the location in the rendered string (à la JavaHelp indexing), but neither seem to work.
Observed in 6.0 development builds of the NetBeans IDE. The menu item File > Project Group > "<html>Advanced Mode <em>(experimental)</em>" uses the mnemonic 'A' but this is not rendered visually.
It seems that BasicMenuItemUI.paintMenuItem normally calls paintText, which in turn calls SwingUtilities2.drawStringUnderlineCharAt; but for HTML labels, javax.swing.text.View.paint is called instead, and this knows nothing about the mnemonic.
---%<---
import javax.swing.*;
import java.awt.event.*;
public class HtmlMnemonic extends JFrame {
private HtmlMnemonic() {
super("HtmlMnemonic");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JMenuBar mb = new JMenuBar();
setJMenuBar(mb);
JMenu m = new JMenu();
mb.add(m);
m.setText("Menu");
m.setMnemonic('M');
JMenuItem mi = new JMenuItem();
m.add(mi);
mi.setText("<html>Foo");
mi.setMnemonic('F');
//mi.setDisplayedMnemonicIndex(0);
//mi.setDisplayedMnemonicIndex(6);
mi.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("menu item selected");
}
});
pack();
}
public static void main(String[] args) {
new HtmlMnemonic().setVisible(true);
}
}
---%<---
Press Alt-M. The menu "_M_enu" will be posted. Press F. "menu item selected" will be printed. But the menu item "Foo" does not display the mnemonic, as in "_F_oo", in contrast to non-HTML labels.
Uncommenting either of the calls to setDisplayedMnemonicIndex does not help. The index 6 ought to correspond to the location of 'F' in the HTML string, while the index 0 ought to correspond to the location in the rendered string (à la JavaHelp indexing), but neither seem to work.
Observed in 6.0 development builds of the NetBeans IDE. The menu item File > Project Group > "<html>Advanced Mode <em>(experimental)</em>" uses the mnemonic 'A' but this is not rendered visually.
It seems that BasicMenuItemUI.paintMenuItem normally calls paintText, which in turn calls SwingUtilities2.drawStringUnderlineCharAt; but for HTML labels, javax.swing.text.View.paint is called instead, and this knows nothing about the mnemonic.