This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Joe Ess
  • salvin francis
  • fred rosenberger

mnemonics and added characters

Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's one for you. Sometimes when I add a mnemonic to a JLabel, the corresponding JTextField gets an added character. That is, if the mnemonic is Alt C for Change, and the user selects Alt C, a C is added to the JTextField.
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is actually a documented java1.2 bug. It has been fixed in java1.3. As yet, I've not been able to find anyone with a good work around.
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also had the same problem. But i used another approach. Instead of the mnemonics, use the keystroke class. It gives you lots of options. Atleast it is working for me.
Pls create a keystroke method and register it to a jbutton, then it will work.
Here is the sample code.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class KeyStrokeSample {
public static void main(String args[]) {
JFrame frame = new ExitableJFrame("KeyStroke Sample");
JButton buttonA = new JButton(
control alt 7");
JButton buttonB =
new JButton(
JButton buttonC =
new JButton(
JButton buttonD =
new JButton(
' '");
// Define ActionListener
ActionListener actionListener =
new ActionListener() {
public void actionPerformed(
ActionEvent actionEvent) {
KeyStroke controlAlt7 = KeyStroke.getKeyStroke(
"control alt 7");
actionListener, controlAlt7, JComponent.WHEN_

KeyStroke enter = KeyStroke.getKeyStroke(
KeyEvent.VK_ENTER, 0, true);
actionListener, enter, JComponent.WHEN_FOCUSED);

KeyStroke shiftF4 = KeyStroke.getKeyStroke(
KeyEvent.VK_F4, InputEvent.SHIFT_MASK);
actionListener, shiftF4,

KeyStroke space = KeyStroke.getKeyStroke(' ');
actionListener, space,

Container contentPane = frame.getContentPane();
contentPane.setLayout(new GridLayout(2,2));
frame.setSize(400, 200);

NOTE: If you try to run the previous program with JFC/Swing release 1.1, a NullPointerException will be generated.

Right! We're on it! Let's get to work tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!