Search code examples
javaswingmenuitemkey-bindings

override display appearance of accelerator keys in JMenuItems in Java/Swing


I've noticed that on some macs the JMenuItem uses the word "space" to indicate that the space bar is the key binding. On other macs a symbol is used (looks like a short capital U). I'd prefer the "space" presentation since it's more transparent to users. Is there any way to override how the LAF graphically represents the accelerator key?


Solution

  • You can subclass BasicMenuItemUI and override the paintMenuItem() method. There you can draw your own accelerator. I would love a animated image as accelerator :)

    (Note If you simply want to change the mneonic or accelerator then you can directly use setAccelerator() or other set methods. But I am assuming this is not the case.)