Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4113639
Votes 0
Synopsis Hotkey labels for menus should be left-aligned
Category java:classes_swing
Reported Against swing1.0fcs
Release Fixed
State 11-Closed, duplicate of 4199382, bug
Priority: 4-Low
Related Bugs 4096574 , 4097435 , 4199382
Submit Date 19-FEB-1998
Description
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 --
Work Around
N/A
Evaluation
This is not as simple as it might appear, since you have to know the
length/size of the text of all sibling menus in order to determine the correct
position for the accelerator text to begin.
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang