Created
February 3, 2015 05:47
-
-
Save skd1993/0f9b193e556859fb65af to your computer and use it in GitHub Desktop.
Display grid over background image using JLayeredPane.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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