Map OSX Command Symbol Character in JLabel

We want to show a hint for JList that the user can select multiple items with a platform-dependent key for the multi selector.

However, I did not find a way to display the OS X COMMAND character in JLabel, which means the character that was typed on the apple keyboard on the command key, also called the apple key.

Here is the symbol that I want to display on OS X. COMMAND SYMBOL

I also want it to be platform independent.

those. sort of

component.add( new JList() , BorderLayout.CENTER );
component.add( new JLabel( MessageFormat.format("With {0} you can " 
  + "select multiple items", 
  KeyStroke.getKeyStroke( ... , ... ) ) ) , BorderLayout.SOUTH );

Where instead of {0} it should appear above the seen symbol ...

Do any of you know how to do this? I know this is possible, since there is a symbol in JMenuItems ...

My own (non-graphical solutions) look like this:

add( new JLabel( MessageFormat.format(
  "With {0} you can select multiple items" , 
  System.getProperty( "mrj.version" ) != null ? "COMMAND" : "CTRL" ) ) ,
  BorderLayout.SOUTH );
+3
source share
4

, , Unicode HTML. , , JLabel HTML, <html> .

JLabel label = new JLabel( "<html>&#8984; is the Apple command symbol." );

Mac, , , , , .

+2

, escape- Unicode \u2318, .

+1

. , , .

add( new JLabel( MessageFormat.format(
  "With {0} you can select multiple items", 
  getMetaKeyHint(),
  BorderLayout.SOUTH );

public String getMetaKeyHint() {
    return System.getProperty( "mrj.version" ) != null ? "COMMAND" : "CTRL" );
}
0

(System.getProperty("os.name").toUpperCase(Locale.US).indexOf("MAC OS X") == 0 )
0

Source: https://habr.com/ru/post/1698631/


All Articles