【发布时间】:2011-09-23 03:09:39
【问题描述】:
我找到了三种方法来填充我的 JFrame frame = 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());
现在我想知道为什么我应该使用 getContentPane()/setContentPane() 方法,如果我可以使用一个简单的 frame.add(...) 来填充我的框架。
【问题讨论】: