Exception : adding a window to a container. How to solve it?

前端 未结 3 379
后悔当初
后悔当初 2020-12-19 21:23

I have a JDialog class named Preferences. This class creates a constructor like:

class Preferences extends javax.swing.JDialog {
           


        
相关标签:
3条回答
  • 2020-12-19 22:03

    JDialog and JFrame are top-level container. I suggest that you should have to use JFrame, JInternalFrame and JDesktopPane.

    0 讨论(0)
  • 2020-12-19 22:14

    You don't add the JDialog to the JFrame, that makes no sense whatsoever since the add(...) method is for adding components to be displayed in the container, not by the container. You display the JDialog from the JFrame's JButton's ActionListener. You also shouldn't be mixing AWT (Frame) components and Swing components together for no good reason.

    Your question suggests that you would benefit greatly by going through the Swing tutorials.

    0 讨论(0)
  • 2020-12-19 22:21

    What does this mean..

    One top level container (dialog) cannot be added to another (frame).

    ..and how can i solve this ?

    Just call setVisible(true) on the Preferences dialog, rather than adding it.

    0 讨论(0)
提交回复
热议问题