Java Swing - how to show a panel on top of another panel?

后端 未结 6 1369
野趣味
野趣味 2020-11-30 03:56

I wish to have an internal (non window) dialog to ask for member input. I would like the dialog to be placed centrally on an existing JPanel.

I have looked at layered

6条回答
  •  天涯浪人
    2020-11-30 04:21

    I just thought that I'd add that there is a notion of Z-order in Swing, see [java.awt.Component#setComponentZOrder][1]

    which affects the positions of a component in its parents component array, which determines the painting order.

    Note that you should override javax.swing.JComponent#isOptimizedDrawingEnabled to return false in the parent container to get your overlapping components to repaint correctly, otherwise their repaints will clobber each other. (JComponents assume no overlapping children unless isOptimizedDrawingEnabled returns false)

    [1]: http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Container.html#setComponentZOrder(java.awt.Component, int)

提交回复
热议问题