[英]Adding a background image to JFrame using JLabel
I added a background image to a JFrame using a JLabel. 我使用JLabel将背景图像添加到JFrame。 But there are other JLabels in a panel added to the particular JFrame. 但是,面板中还有其他JLabel添加到了特定的JFrame。 After adding this background image all over the JFrame, other JLabels are not visible. 在整个JFrame中添加此背景图像之后,其他JLabel将不可见。 How do I get them be visible? 如何使它们可见?
Several options: 几种选择:
getPreferredSize()
override that makes sense in the context of your problem (JLabel's own override for this method won't work for you, since it depends on text and icons that the label holds and not on components added). 使JLabel不透明并使其成为contentPane,使其具有适当的布局,使其具有适当的getPreferredSize()
覆盖,该覆盖在您的问题上下文中是有意义的(JLabel对此方法的自身覆盖对您不起作用,因为这取决于标签所包含的文字和图标上,而不是添加的组件上)。 Or: 要么:
paintComponent(...)
method override. 在其paintComponent(...)
方法替代中显示图像。 getPreferredSize()
override. 给它合适的布局管理器,并在需要时重写getPreferredSize()
。 Also: 也:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.