Class JImagePanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public final class JImagePanel extends JPanel
The JImagePanel class provides a JPanel with a background image.

Currently, only GIF, JPG or PNG images are allowed.

Note that this class cannot be subclassed!

Version:
19/11/2011
Author:
Sven Maerivoet
See Also:
  • Constructor Details

    • JImagePanel

      public JImagePanel(String imageFilename) throws FileReadException
      Constructs a JImagePanel object with the image in the specified file as its background.

      Only GIF, JPG or PNG images are allowed.

      Note that a FileReadException is thrown when the image file cannot be read.

      Parameters:
      imageFilename - the name of the file containing the background image
      Throws:
      FileReadException - if the specified image file cannot be read
    • JImagePanel

      public JImagePanel(Image backgroundImage)
      Constructs a JImagePanel object with a specified Image.

      Only GIF, JPG or PNG images are allowed.

      Parameters:
      backgroundImage - the background Image
  • Method Details

    • retainAspectRatio

      public void retainAspectRatio()
      Makes sure that the aspect ratio is maintained when the image is shown.
    • imageUpdate

      public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
      Blocks (re)painting of the image until it's completely loaded.
      Specified by:
      imageUpdate in interface ImageObserver
      Overrides:
      imageUpdate in class Component
    • paintComponent

      public void paintComponent(Graphics g)
      Paints the image on the canvas.
      Overrides:
      paintComponent in class JComponent