0

I tried using the Jlabel I set the layout to null and placed the background image it works but whenever I try to run it's not full size how do I fix this? This is the output window would show this.

I would still have to expand the window:

https://i.stack.imgur.com/3IlKV.png

Has a Gray Scale

https://i.stack.imgur.com/H1dSI.png

can anyone help me.

Misa Lazovic
  • 2,805
  • 10
  • 32
  • 38
  • This could help ? http://stackoverflow.com/questions/23322564/how-to-make-the-image-scale-its-size-automatically-according-to-the-parent-jlabe – sean Nov 17 '15 at 03:27

1 Answers1

0

I set the layout to null

Don't use a null layout on the frame. The pack() method will only work when the panels use layout managers.

Has a Gray Scale

A JLabel will only paint the image at its actual size.

If you want the image to scale then you need to do custom painting.

One way to do this is to override the paintComponent() method of a JPanel than you draw the image manually using:

Dimension d = getSize();
g.drawImage(image, 0, 0, d.width, d.height, this);

Then you can set the layout to whatever you want and add components to the panel.

Or you could use the Background Panel which will do this for you. It also provides an to tile the image

Another option is to use Darryl's Stretch Icon. This will allow the Icon to fill the space of the label.

camickr
  • 321,443
  • 19
  • 166
  • 288