Skip to content

Instantly share code, notes, and snippets.

@skd1993
Created February 3, 2015 05:47
Show Gist options
  • Save skd1993/0f9b193e556859fb65af to your computer and use it in GitHub Desktop.
Save skd1993/0f9b193e556859fb65af to your computer and use it in GitHub Desktop.
Display grid over background image using JLayeredPane.
JLayeredPane layers = new JLayeredPane();
layers.setPreferredSize( new Dimension( GRID_SIZE, GRID_SIZE ) );
layers.setLayout(new FlowLayout());
BufferedImage backgroundImage = null;
try{ backgroundImage = ImageIO.read(new File("resources/Background.png"));}
catch(IOException ex){
System.out.println(ex);
}
JLabel bImage = new JLabel(new ImageIcon(backgroundImage));
JPanel grid = createGrid(); //creates a grid the same size as the image (500,500)
grid.setBackground(new Color(0,0,0,125));
layers.add(bImage, new Integer(1));
layers.add(grid, new Integer(2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment