Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JavaEclipse中将背景添加到JPANEL中_Java_Swing_Jpanel_Layout Manager - Fatal编程技术网

在JavaEclipse中将背景添加到JPANEL中

在JavaEclipse中将背景添加到JPANEL中,java,swing,jpanel,layout-manager,Java,Swing,Jpanel,Layout Manager,我试图将互联网上的背景图像添加到我的JPanel,但只有addJFramebackground的源代码,没有任何addJPanelbackground的源代码。请帮忙 我尝试了ImageImage=ImageIO.read(新文件(“resources/2.png”)也是,但仍然失败 我的Jpanel代码: contentPane = new JPanel(); contentPane.setBackground(new Color(32, 178, 170)); con

我试图将互联网上的背景图像添加到我的
JPanel
,但只有add
JFrame
background的源代码,没有任何add
JPanel
background的源代码。请帮忙

我尝试了Image
Image=ImageIO.read(新文件(“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")));
并将标签添加到面板中