Netbean Java Swing, JPanel/Jlabel Cant cover whole Frame
Solution 1:
Here's what I would do. Use a JPanel
for the background and throw in some custom paint code.
Drag a
JPanel
to the form and expand that to cover the whole frame, to be the background.-
Right click on the
JPanel
and select Customize Code from the context menu. You will see the following dialog. You can now edit the code. -
Make sure to select custom creation from the drop down and type this
jPanel1 = new JPanel() { BufferedImage img; { try { img = ImageIO.read(getClass().getResource("/resources/stackoverflow5.png")); } catch (IOException ex) { ex.printStackTrace(); } } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(img, 0, 0, getWidth(), getHeight(), this); } };
You probably will have to resolve imports. Just hit Ctrl + Shift + I
Also you will have to change the path of the image to your path.
Here's my file structure
And here's the result