简体   繁体   English

将图像添加到GUI

[英]Adding Image to GUI

I'm having troubles here with adding photos into my GUI. 我在将照片添加到GUI时遇到了麻烦。 I have created a JPanel and im using that to add my photos in. However, when i uncomment line 156, everything in my GUI is gone except for the photo. 我创建了一个JPanel,并使用im来添加照片。但是,当我取消注释第156行时,GUI中除照片之外的所有内容都消失了。

Im referring to line 149-156. 我指的是第149-156行。

http://pastie.org/private/znexgtf7uskpapd4cuaoq#146,153 http://pastie.org/private/znexgtf7uskpapd4cuaoq#146,153

Your contentPane panel uses a BorderLayout and because of that when you uncomment the line contentPane.add(panel_4); 您的contentPane面板使用BorderLayout ,因此,当取消注释行contentPane.add(panel_4);时,此面板将使用BorderLayout contentPane.add(panel_4); panel panel_4 will replace the previous panel that was set as BorderLayout.CENTER which in this case is tabbedPane . panel panel_4将替换先前设置为BorderLayout.CENTER面板,在本例中为tabbedPane

As is mentioned in the documentation for BorderLayout : BorderLayout 文档中所述:

Each region may contain no more then one container. 每个区域最多只能容纳一个容器。 ..... BorderLayout interprets the absence of a string specification the same as the constant CENTER ..... BorderLayout解释缺少与常量CENTER相同的字符串规范

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM