Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><em>Update 2013-06-21: this answer contains some workarounds and alternatives that may be useful, but <a href="https://stackoverflow.com/a/17226346/31440">@sidney-markowitz-biomatters' answer</a> contains the correct code fix - the LAF needs to be set from the event thread!</em></p> <p>The recent problems seem to be related to the updates breaking the Aqua Look and Feel (LAF), which is the default for Swing apps on Mac OS X.</p> <p>If you need the Aqua LAF then there are not too many options. You might need to wait for the next Java update from Apple (I'm assuming they will fix this with priority, given it's their own LAF). You could also try using the <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html" rel="nofollow noreferrer">Java Application Bundler</a> (i.e. bundle the Oracle JRE and avoid using the system's JRE).</p> <p>If you can get by with a different LAF then your app should work as normal. It did for <a href="http://www.papercut.com/kb/Main/UserClientIssuesInMacOSXJune2013" rel="nofollow noreferrer">PaperCut</a>, at least (the 003 update caused some window focus problems, the 004 update caused mayhem).</p> <p>Some options:</p> <ul> <li><p><strong>Using the Java <a href="http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html" rel="nofollow noreferrer">version-specific</a> cross platform LAF from Java code (e.g. Nimbus or Metal):</strong></p> <pre class="lang-java prettyprint-override"><code>UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()) </code></pre></li> <li><p><strong>Setting a specific LAF from Java code:</strong></p> <pre class="lang-java prettyprint-override"><code>UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel") </code></pre></li> <li><p><strong>Overriding the default LAF from terminal:</strong></p> <pre class="lang-sh prettyprint-override"><code>java -Dswing.defaultlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel MyApp </code></pre></li> </ul> <p>In our case we were explicitly calling <code>UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())</code> in our code and wanted a workaround that didn't involve a code change (i.e. a hotfix), so we needed to override the default <em>system</em> LAF as follows.</p> <ul> <li><p><strong>Overriding the system LAF from terminal:</strong></p> <pre class="lang-sh prettyprint-override"><code>java -Dswing.systemlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel ... </code></pre></li> <li><p><strong>Overriding the system LAF from an <code>Info.plist</code> file</strong> (if you have bundled as a Mac application, also works for the other VM options) (e.g. at <code>My.app/Contents/Info.plist</code>).</p> <p>You want to add <code>-Dswing.systemlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel</code> to the <em>end</em> of the <code>&lt;string&gt;</code> value for the <code>VMOptions</code> <code>&lt;key&gt;</code>. The options are space separated, just like from the terminal. E.g. if you already have a <code>useScreenMenuBar</code> option:</p> <pre class="lang-xml prettyprint-override"><code>&lt;key&gt;VMOptions&lt;/key&gt; &lt;string&gt;-Dcom.apple.macos.useScreenMenuBar=true -Dswing.systemlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel&lt;/string&gt; </code></pre></li> </ul> <p><br /></p> <p><strong>Edit: @trashgod asked for a reproducible example. I'm not sure what the full scope of the problems with the 004 update are, but here's a simple reproduction:</strong></p> <p><em>Update 2013-06-21 - the wrong way, reproducing the error:</em></p> <pre class="lang-java prettyprint-override"><code>public class AquaLafTest { public static void main(String[] args) throws Exception { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); javax.swing.JOptionPane.showMessageDialog(null, "msg"); } } </code></pre> <ol> <li><p>Run with the Apple JRE that comes with the 004 update (e.g. at <code>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home</code>). Observe that the message is not visible, the dialog icon is not visible and the button is not visibly clickable.</p></li> <li><p>Run with an older Apple JRE or another JRE. Observe that the dialog displays as expected.</p></li> </ol> <p><em>Update 2013-06-21 - the right way, on the event thread, works correctly:</em></p> <pre class="lang-java prettyprint-override"><code>public class AquaLafTest { public static void main(String[] args) throws Exception { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { try { javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName()); javax.swing.JOptionPane.showMessageDialog(null, "msg"); } catch (Exception e) { e.printStackTrace(); } } }); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload