so I've been working on my program and I am having trouble getting setting up a JFrame with a background image of a network map and then setting a JPanel using a MigLayout on top of the JFrame which will allow me to place images in accordance to the network map. I have seen several different ways on how to set a background image and have tried using an example I found elsewhere on this site but it's not quite working. Also, I researched more on this and found that having a JPanel ontop of a JFrame may prevent the JFrame background image from being seen. I was hoping that someone could take a look at my code and let me know if that is the case.
Here is my class to set the background:
public class bwMonBackground extends JFrame {
Image img;
public bwMonBackground() {
try {
img = ImageIO.read(new File("/Users/pwopperer/workspace/BWmon/src/customer_vlans.jpg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void paintComponent(Graphics g)
{
super.paintComponents(g);
g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
}
}
Here is my main:
public class bwMonBackgroundMain {
public static void main( String[] args )
{
bwMonBackground frame = new bwMonBackground();
frame.setLayout(new FlowLayout(FlowLayout.LEFT,10,20));
migLayout testing = new migLayout();
frame.add(testing.createLayout());
frame.setVisible(true);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
}
}
EDIT: When I run it like this, I only get a JPanel with the 6 JLabels I added into it