問題ないようです...
public class TestLayeredDialog {
public static void main(String[] args) {
new TestLayeredDialog();
}
public TestLayeredDialog() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
JDialog dialog = new JDialog();
dialog.setModal(true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setLayout(new BorderLayout());
dialog.add(new MyContent());
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
System.exit(0);
}
});
}
public class MyContent extends JLayeredPane {
public MyContent() {
JLabel label = new JLabel("Hello new world");
label.setSize(label.getPreferredSize());
label.setLocation(0, 0);
add(label);
Dimension size = getPreferredSize();
JButton button = new JButton("Click me");
button.setSize(button.getPreferredSize());
button.setLocation(size.width - button.getWidth(), size.height - button.getHeight());
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SwingUtilities.getWindowAncestor(MyContent.this).dispose();
}
});
add(button);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(200, 200);
}
}
}
JLayeredPane
レイアウトマネージャーがないことを忘れないでください。子コンポーネントのサイズと位置を管理する責任があります。それがポイントです。
新しい例で更新

public class TestLayeredDialog {
public static void main(String[] args) {
new TestLayeredDialog();
}
public TestLayeredDialog() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
JDialog dialog = new JDialog();
dialog.setModal(true);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setLayout(new BorderLayout());
JLabel label = new JLabel("Hello new world");
label.setSize(label.getPreferredSize());
label.setLocation(0, 0);
dialog.getLayeredPane().add(label, new Integer(1));
dialog.setSize(100, 100);
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
System.exit(0);
}
});
}
}
の階層化されたペインは、JRootPane
(とりわけ)コンテンツペインとメニューバーのレイアウトを担当します。また、ポップアップなどを表示するためにも使用されます(場合によっては)。

ルートペインの使用方法をお読みください
ルートペインの階層化ペインにコンポーネントを配置することを選択できます。その場合、特定の深さが特定の機能に使用されるように定義されていることに注意する必要があります。また、意図したとおりに深さを使用する必要があります。そうしないと、コンポーネントが他のコンポーネントとうまく機能しない可能性があります。これは、機能レイヤーとそれらの関係を示す図です。
これを使用すると、すでに画面に表示されているコンポーネントと競合していることを意味します。
このコンポーネントをいじる正当な理由がない限り、1-将来変更される可能性があり(コンポーネントのレイヤー位置)、2-使用される他のコンポーネントと干渉する可能性があるため、避けることをお勧めします。 Swing API