Setting System Properties in Groovy

Please note:. Although I mention Swing and MacOS here, this question has nothing to do with any of them: I just provide them as a concrete example of what I'm trying to do.


I am trying to set the groovy system property. If you are developing a Swing application on a Mac, it is common practice to set the following system property to make your Swing application menu look like regular Mac applications:

System.setProperty("apple.laf.useScreenMenuBar", "true") 

When I call this inside my main method, it has the desired effect (the menu bar is removed from the JFrame and docked at the top of the screen).

But when I go try to make this groovier call:

 System.properties['apple.laf.useScreenMenuBar', 'true'] 

he does not work. No exceptions, it just stops working and does not have the desired effect in the user interface. Why and what can I do to fix this?

+5
source share
1 answer

Must be:

 System.properties['apple.laf.useScreenMenuBar'] = true 

or

 System.properties.'apple.laf.useScreenMenuBar' = true 

In this code snippet:

 System.properties['apple.laf.useScreenMenuBar', 'true'] 

['apple.laf.useScreenMenuBar', 'true'] is taken for the key. See below:

 def m = [ [1, 2,]:3, 2:4 ] assert m[1, 2] == 3 

The following code snippet returns the correct results:

 System.properties['lol'] = 2 assert 2 == System.properties['lol'] 
+12
source

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


All Articles