- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在这段代码中:
JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(175, 100));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
我可以看到它创建了一个新标签并将其添加到 JFrame
对象 frame
中。但我想了解 getContentPane()
做了什么,为什么需要它?
我读了this API但我还是不明白。
最佳答案
每个 Swing 顶级容器(和 JInternalFrame)都有所谓的 JRootPane
。它负责实际管理窗口的整体布局。
根 Pane 有许多层,其中一层是内容 Pane 。当您向框架添加内容时(我认为是从 Java 5 开始),它会自动为您添加到内容 Pane 中,在此之前,您必须调用 getContentPane().add(...)
你自己
关于Java 图形用户界面 : about getContentPane( ) method and content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16744152/
我做了一些研究来了解 JFrame 的使用及其部件,我发现了以下信息: 1- JFrame 的部分 根 Pane 菜单裸露 内容 Pane 玻璃板 2- JFrame 实现 RootPaneConta
我创建了一个扩展 JFrame 的类,默认情况下它会创建一个 JPanel。我试过这个: public class Main extends JFrame { JPanel pane; private
何时使用: Container c = getContentPane(); 以及何时使用: frame.getContentPane(); 最佳答案 getContentPane().setBackg
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我有一个扩展 JPanel 并绘制三角形的类。我从其他类(class)调用它来创建三个三角形,但是当绘制第三个三角形时,前两个三角形消失了。如何添加一起显示的多个三角形。代码如下: 三角形.Java:
我这里有一个代码,但我收到了这个错误。如何修复以下代码的错误? Container container = getContentPane(); 这是运行代码。 import java.awt.Bord
我正在处理我的作业,其中一部分要求我在 JFrame 的网格布局中放置一个红色 block 。之后,用户应该能够通过箭头键更改该红色 block 的位置。 到目前为止,我已经能够将红色 block 添
我创建的这些脚本遇到了一些(非常烦人的)问题。 Sburb.java import java.awt.Color; import javax.swing.*; public class Sburb {
我想从内部 Action 类调用外部类的方法 getContentPane()。我不明白为什么我的代码不起作用。 public class MainFrame extends JFrame {
我找到了三种方法来填充我的 JFrame frame = new JFrame("...")createContentPanel 返回一个 JPanel,createToolBar 返回一个 Tool
在这段代码中: JLabel emptyLabel = new JLabel(""); emptyLabel.setPreferredSize(new Dimension(175, 100)); fr
我访问过很多有关 Java Swing 的教程,我想知道使用 .getContentPane().add(); 添加组件之间的区别或使用.add() ,哪个是最好的? (如果还有“更好”的话)。 最佳
如果这有助于解决问题,我可以提供所有代码,但我相信,由于这实际上只影响一个类,因此可以在这里解决它,以简化问题。 我有一个 Solitaire 项目(注意包/类名称,这是反复试验,我没有删除旧项目),
java swing 中的静态上下文错误无法引用非静态方法 getContentPane() import javax.swing.*; import java.awt.*; import java.
我刚刚开始使用 pro Window Builder 创建 java GUI,默认情况下创建了 JFrame 和 getContentPane 面板,在我继续创建另一个具有卡片布局的 mainPane
在一个 JFrame 中,我用另一个 JPanel 替换了一个 Jpanel 。 package testing; import java.io.*; import java.util.*; impo
我有一个扩展JFrame的类Window和一个扩展JPanel的类Content。 Content 对象被添加到 Window 对象中。 类窗口: public class Window extend
这个问题的标题不言自明。我正在使用 JFrame 制作扫雷的克隆,并且刚刚完成玩家选择游戏大小的起始屏幕。单击按钮时,框架应该会为游戏屏幕做好准备。当我单击一个按钮时,该按钮仍处于“按下”状态并且 J
我发现我可以轻松使用(JPanel)frame.getContentPane()作为默认层JPanel,即使有边框。 (一开始这让我感到惊讶。) 这是一种常见/不常见/好/坏行为吗?为什么?执行此操作
我知道,as of Java 1.5 ,可以像这样将组件添加到 JFrame: myFrame.add(myButton); 代替: myFrame.getContentPane().add(myBu
我是一名优秀的程序员,十分优秀!