我在将照片添加到 GUI 时遇到了麻烦。我创建了一个 JPanel,并使用它来添加我的照片。但是,当我取消注释第 156 行时,除了照片之外,GUI 中的所有内容都消失了。
我指的是第 149-156 行。
最佳答案
您的 contentPane
面板使用 BorderLayout
,因此当您取消注释行 contentPane.add(panel_4);
panel panel_4
将替换之前设置为 BorderLayout.CENTER
的面板,在本例中为 tabbedPane
。
正如 documentation 中提到的对于 BorderLayout
:
Each region may contain no more then one container. ..... BorderLayout interprets the absence of a string specification the same as the constant CENTER
关于java - 将图像添加到 GUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28393730/