Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Answering my own question:</p> <p><a href="http://download.oracle.com/javase/6/docs/api/java/awt/Container.html#add%28java.awt.Component,%20int%29">Container.add(Component, int)</a> and <a href="http://download.oracle.com/javase/6/docs/api/java/awt/Container.html#setComponentZOrder%28java.awt.Component,%20int%29">Container.setComponentZOrder(Component, int)</a> are virtually identical. The former invokes removeNotify() while the latter does not (for performance reasons).</p> <p>Container-layering only works if <a href="http://download.oracle.com/javase/6/docs/api/javax/swing/JComponent.html#isOptimizedDrawingEnabled%28%29http://download.oracle.com/javase/6/docs/api/javax/swing/JLayeredPane.html#isOptimizedDrawingEnabled%28%29">JComponent.isOptimizedDrawingEnabled()</a> returns false. One implementation that just-so-happens to return false is... you guessed it: <a href="http://download.oracle.com/javase/6/docs/api/javax/swing/JLayeredPane.html">JLayeredPane</a></p> <p>Using Container-layering is discouraged because it can have <a href="http://download.oracle.com/javase/6/docs/api/javax/swing/JLayeredPane.html">unexpected side-effects</a>.</p> <p>Finally, it is worth noting that while Container declares <a href="http://download.oracle.com/javase/6/docs/api/java/awt/Container.html#add%28java.awt.Component,%20int%29">add(Component, int)</a> it doesn't actually paint layered components properly. <a href="http://download.oracle.com/javase/6/docs/api/javax/swing/JComponent.html">JComponent</a> and its subclasses do.</p> <p>Another interesting find: never invoke repaint() on a child of JLayeredPane. This will cause the component to paint itself on top regardless of its z-order. You should only invoke repaint() on the JLayeredPane itself.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. CORe "never invoke repaint() on a child of JLayeredPane": I'm curious about what type of child component you found this with. I ran into [a similar problem](http://stackoverflow.com/questions/5668721/jmenuitems-painting-over-higher-components-in-jlayeredpane) and determined that, in my case at least, it was an issue with JMenuItems specifically. They behave as if they're always on top (unless they're transparent).
      singulars
    2. CO@Aaron, I don't remember which component I used but when you think about it it makes sense that all components will behave they are always on top. paint() is meant to assume that you will set the clip bounds to prevent it from drawing outside the desired bounds. When you invoking repaint() directly on a child component (with no bounds) you are essentially asking for it to ignore its parent. In other words, this isn't a bug in the Swing implementation. It's user error.
      singulars
    3. COActually that's not correct. See [Painting in AWT and Swing](http://java.sun.com/products/jfc/tsc/articles/painting/), specifically the Paint Processing section. It states that when `repaint()` is called on a JComponent, the RepaintManager uses the clip rectangle and the component's `opaque` and `isOptimizedDrawingEnabled` properties to determine the 'root' component from which the paint operation must begin. Most components, in fact, do not behave as if they're always on top (i.e. `alwaysOnTop()` returns `false` by default).
      singulars
 

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