小编fro*_*hli的帖子

JAVA:填充框架的方法.add(),setContentPane(),getContentPane()

我找到了三种方法来填充我的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(...)来填充我的框架.

java jframe jtoolbar

13
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×1

jframe ×1

jtoolbar ×1