-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
sparc
-
solaris_2.6
Hotkey labels for menus should be left-aligned to give them a professional look.
Steps to reproduce the problem.
1. Run the application for which the sample code is given below.
2. Click on the menu - The hot-key labels Ctrl-C. Ctrl-X, Ctrl-V, Delete are not aligned properly.
-- Sample Code --
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class TestJMenu17 extends JFrame implements ActionListener{
/*************************************** Bug Description ***************************************/
String[] strBugDesc = { "",
"",
"",
"",
"This TestCase tests the JMenu Component",
"",
"",
"**Problem : ** Hot-key labels are not left-aligned.",
"",
"",
"Steps to reproduce :",
"1. Click on the menu, and the menu items drop down.",
"2. The hotkey labels - Ctrl-X, Ctrl-C, Ctrl-V and Delete are not left aligned.",
"3. Can also check for different L&N by selecting from the toolbar.",
"",
"",
"",
""};
/*************************************** Bug Description ***************************************/
Container content;
JToolBar toolbar;
JMenuBar mbar;
static String strMotif = "Motif";
static String motifClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
static String strWindows = "Windows";
static String windowsClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
static String strMetal = "Metal";
static String metalClassName = "com.sun.java.swing.plaf.metal.MetalLookAndFeel";
static String[] strData = {"Cut", "Copy", "Paste", "Delete"};
static char[] mnData = {'C', 'o', 'P', 'D'};
TestJMenu17(String[] args) {
displayBugDesc();
content = getContentPane();
content.setLayout(new BorderLayout(8, 8));
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event){
System.exit(0);
}
}
);
toolbar = CreateToolBar();
content.add("North", toolbar);
content.add("Center", getMyMenuBar());
pack();
show();
}
public void displayBugDesc() {
int n = strBugDesc.length;
System.out.println("/******************************* Bug Description and Comments *******************************/");
System.out.println();
for(int i = 0; i < n; i ++) {
System.out.println(strBugDesc[i]);
}
System.out.println();
System.out.println("/******************************* Bug Description and Comments *******************************/");
}
public JMenuBar getMyMenuBar() {
JMenuBar menubar;
JMenu menu;
JMenuItem menuitem;
int i = 0;
menubar = new JMenuBar();
menu = new JMenu("Edit");
menu.setMnemonic('E');
menuitem = new JMenuItem(strData[i]);
menuitem.setMnemonic(mnData[i]);
menuitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
menuitem.addActionListener(this);
menu.add(menuitem);
i ++;
menuitem = new JMenuItem(strData[i]);
menuitem.setMnemonic(mnData[i]);
menuitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
menuitem.addActionListener(this);
menu.add(menuitem);
i ++;
menuitem = new JMenuItem(strData[i]);
menuitem.setMnemonic(mnData[i]);
menuitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
menuitem.addActionListener(this);
menu.add(menuitem);
i ++;
menuitem = new JMenuItem(strData[i]);
menuitem.setMnemonic(mnData[i]);
menuitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, KeyEvent.CHAR_UNDEFINED));
menuitem.addActionListener(this);
menu.add(menuitem);
menubar.add(menu);
return menubar;
}
public JToolBar CreateToolBar() {
JToolBar tbar = new JToolBar();
JButton bn;
bn = new JButton(strWindows);
bn.addActionListener(this);
bn.setActionCommand(windowsClassName);
tbar.add(bn);
bn = new JButton(strMotif);
bn.addActionListener(this);
bn.setActionCommand(motifClassName);
tbar.add(bn);
bn = new JButton(strMetal);
bn.addActionListener(this);
bn.setActionCommand(metalClassName);
tbar.add(bn);
return tbar;
}
public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
if(str.equals(strData[0]) || str.equals(strData[1]) || str.equals(strData[2]) || str.equals(strData[3])) {
System.out.println("Action Event : " + e.paramString());
}
else {
try {
UIManager.setLookAndFeel(str);
SwingUtilities.updateComponentTreeUI(TestJMenu17.this);
TestJMenu17.this.pack();
}
catch (Exception exc) {
System.err.println("Could not load LookAndFeel: " + str);
}
}
}
// Main funtion
public static void main(String[] args) {
TestJMenu17 test = new TestJMenu17(args);
}
}
-- Sample Code --
Steps to reproduce the problem.
1. Run the application for which the sample code is given below.
2. Click on the menu - The hot-key labels Ctrl-C. Ctrl-X, Ctrl-V, Delete are not aligned properly.
-- Sample Code --
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class TestJMenu17 extends JFrame implements ActionListener{
/*************************************** Bug Description ***************************************/
String[] strBugDesc = { "",
"",
"",
"",
"This TestCase tests the JMenu Component",
"",
"",
"**Problem : ** Hot-key labels are not left-aligned.",
"",
"",
"Steps to reproduce :",
"1. Click on the menu, and the menu items drop down.",
"2. The hotkey labels - Ctrl-X, Ctrl-C, Ctrl-V and Delete are not left aligned.",
"3. Can also check for different L&N by selecting from the toolbar.",
"",
"",
"",
""};
/*************************************** Bug Description ***************************************/
Container content;
JToolBar toolbar;
JMenuBar mbar;
static String strMotif = "Motif";
static String motifClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
static String strWindows = "Windows";
static String windowsClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
static String strMetal = "Metal";
static String metalClassName = "com.sun.java.swing.plaf.metal.MetalLookAndFeel";
static String[] strData = {"Cut", "Copy", "Paste", "Delete"};
static char[] mnData = {'C', 'o', 'P', 'D'};
TestJMenu17(String[] args) {
displayBugDesc();
content = getContentPane();
content.setLayout(new BorderLayout(8, 8));
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event){
System.exit(0);
}
}
);
toolbar = CreateToolBar();
content.add("North", toolbar);
content.add("Center", getMyMenuBar());
pack();
show();
}
public void displayBugDesc() {
int n = strBugDesc.length;
System.out.println("/******************************* Bug Description and Comments *******************************/");
System.out.println();
for(int i = 0; i < n; i ++) {
System.out.println(strBugDesc[i]);
}
System.out.println();
System.out.println("/******************************* Bug Description and Comments *******************************/");
}
public JMenuBar getMyMenuBar() {
JMenuBar menubar;
JMenu menu;
JMenuItem menuitem;
int i = 0;
menubar = new JMenuBar();
menu = new JMenu("Edit");
menu.setMnemonic('E');
menuitem = new JMenuItem(strData[i]);
menuitem.setMnemonic(mnData[i]);
menuitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
menuitem.addActionListener(this);
menu.add(menuitem);
i ++;
menuitem = new JMenuItem(strData[i]);
menuitem.setMnemonic(mnData[i]);
menuitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
menuitem.addActionListener(this);
menu.add(menuitem);
i ++;
menuitem = new JMenuItem(strData[i]);
menuitem.setMnemonic(mnData[i]);
menuitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
menuitem.addActionListener(this);
menu.add(menuitem);
i ++;
menuitem = new JMenuItem(strData[i]);
menuitem.setMnemonic(mnData[i]);
menuitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, KeyEvent.CHAR_UNDEFINED));
menuitem.addActionListener(this);
menu.add(menuitem);
menubar.add(menu);
return menubar;
}
public JToolBar CreateToolBar() {
JToolBar tbar = new JToolBar();
JButton bn;
bn = new JButton(strWindows);
bn.addActionListener(this);
bn.setActionCommand(windowsClassName);
tbar.add(bn);
bn = new JButton(strMotif);
bn.addActionListener(this);
bn.setActionCommand(motifClassName);
tbar.add(bn);
bn = new JButton(strMetal);
bn.addActionListener(this);
bn.setActionCommand(metalClassName);
tbar.add(bn);
return tbar;
}
public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
if(str.equals(strData[0]) || str.equals(strData[1]) || str.equals(strData[2]) || str.equals(strData[3])) {
System.out.println("Action Event : " + e.paramString());
}
else {
try {
UIManager.setLookAndFeel(str);
SwingUtilities.updateComponentTreeUI(TestJMenu17.this);
TestJMenu17.this.pack();
}
catch (Exception exc) {
System.err.println("Could not load LookAndFeel: " + str);
}
}
}
// Main funtion
public static void main(String[] args) {
TestJMenu17 test = new TestJMenu17(args);
}
}
-- Sample Code --
- duplicates
-
JDK-4199382 Swing Menus - text/icon/checkmark alignment schemes severely broken
- Closed
- relates to
-
JDK-4096574 JMenuItem does not allow users to specify a hot-key label
- Closed
-
JDK-4097435 JFC should provide independent notions of menu shortcuts and hot keys
- Closed