我尝试将互联网上的背景图像添加到我的 JPanel
中,但只有用于添加 JFrame
背景的源代码,并且没有任何用于添加 的源代码JPanel
背景。请帮忙。
我也尝试了图像 image= ImageIO.read(new File("resources/2.png"));
但仍然失败。
我的 Jpanel 代码:
contentPane = new JPanel();
contentPane.setBackground(new Color(32, 178, 170));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);;
最佳答案
使用Jlabel
并向其中添加图像。像这样的事情:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/yourImage.jpg")));
并向面板添加标签。
关于java - 在JAVA Eclipse中添加背景到JPANEL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25461595/