Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot mix lightweight and heavyweight components in an undecorated JFrame
    primarykey
    data
    text
    <p>I am attempting to mix heavyweight and lightweight components according to <a href="http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html" rel="nofollow">these</a> guidelines.</p> <p>I am expecting the following code to paint the entire window green. Instead, it renders half the screen red:</p> <pre><code>import java.awt.Canvas; import java.awt.Color; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JLayeredPane; import javax.swing.JPanel; public class Testcase extends Canvas { private static final long serialVersionUID = 0L; public static void main(String[] arg) { final boolean enableWorkaround = false; EventQueue.invokeLater(new Runnable() { @Override public void run() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JLayeredPane layers = new JLayeredPane(); frame.getContentPane().add(layers); JPanel green = new JPanel(); green.setBackground(Color.GREEN); green.setBounds(0, 0, 800, 600); layers.add(green, Integer.valueOf(1)); Canvas red = new Canvas(); red.setBackground(Color.RED); red.setBounds(0, 0, 400, 600); layers.add(red, Integer.valueOf(0)); frame.setSize(800, 600); if (!enableWorkaround) frame.setUndecorated(true); frame.setVisible(true); } }); } } </code></pre> <p>Reproduced on:</p> <pre><code>java version "1.6.0_23" Java(TM) SE Runtime Environment (build 1.6.0_23-b05) Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing) </code></pre> <p>and</p> <pre><code>java version "1.7.0-ea" Java(TM) SE Runtime Environment (build 1.7.0-ea-b124) Java HotSpot(TM) Client VM (build 20.0-b05, mixed mode, sharing) </code></pre> <p>Does my code contain any bugs or is this a legitimate JDK bug?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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