Note that there are some explanatory texts on larger screens.

plurals
  1. POJFrame gets decorated with Windows borders, even the Look&Feel is set otherwise
    primarykey
    data
    text
    <p>Good day everyone.</p> <p>First of all: check this image. <img src="https://s12.postimg.org/dq84ycs5p/weird_frames.png" alt=""></p> <p>Please note that in the first of the 3 frames, the button is styled with Metal Look and Feel, but the frame is Windows styled. The other 2 frames are "OK" in the sence that the button LAF matches the frame LAF.</p> <p>The code for all of these (same order as the images):</p> <pre><code>public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame frame = new JFrame(); frame.getContentPane().add(new JButton("button")); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame frame = new JFrame(); frame.setUndecorated(true); frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME); frame.setSize(100, 100); frame.getContentPane().add(new JButton("button")); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { // 0 =&gt; "javax.swing.plaf.metal.MetalLookAndFeel" // 3 =&gt; the Windows Look and Feel String name = UIManager.getInstalledLookAndFeels()[3].getClassName(); UIManager.setLookAndFeel(name); } catch (Exception ex) { ex.printStackTrace(); } JFrame frame = new JFrame(); frame.getContentPane().add(new JButton("button")); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); } </code></pre> <p>Now what bothers me is that I have never been forced to use the lines <code>frame.setUndecorated(true); frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);</code>, as setting the Look and Feel just worked with the <code>UIManager.setLookAndFeel()</code> method. Normally, the JFrame itself would get styled too, but this seems not longer the case as I get a Windows styled frame (1st image, 1 code snippet).</p> <p>Why is this? Is this new in Java 7? This seems really weird.</p> <p>Normally, without touching code that involves Look and Feel, the program should start with the Metal Look and Feel, as this is the standard Java Look and Feel. So why does the first program start with a Windows frame?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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