我找到了三种方法来填充我的JFrame框架= new JFrame("...")createContentPanel返回一个JPanel,createToolBar返回一个ToolBar.
frame.add(this.createToolBar(), BorderLayout.PAGE_START); //this works and puts the ToolBar above and the ContentPanel under it<br>
frame.add(this.createContentPanel(), BorderLayout.CENTER);
frame.setContentPane(this.createContentPanel()); //this lets the JToolBar hover over the ContentPanel
frame.getContentPane().add(this.createToolBar());
frame.getContentPane().add(this.createContentPanel()); //this only puts the last one into the JFrame
frame.getContentPane().add(this.createToolBar());
Run Code Online (Sandbox Code Playgroud)
现在我想知道为什么我应该使用getContentPane()/ setContentPane()方法,如果我可以使用一个简单的frame.add(...)来填充我的框架.