This program will work perfectly and print out the JLabel if it is just a string, but if I try using an ImageIcon nothing will display.
Here is the class of evil:
public class Window extends JFrame{
JPanel panel;
ImageIcon imgIcon;
JLabel label;
public Window(String name){
super(name);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationByPlatform(true);
//addKeyListener(new KeyboardInput());
panel = new JPanel();
panel.setLayout(null);
imgIcon = new ImageIcon("rorschach.jpg");
label = new JLabel();
label.setIcon(imgIcon);
label.setLocation(0,0);
label.setSize(label.getPreferredSize());
panel.add(label);
add(panel);
setVisible(true);
}
public static void main(String[] args){
Window window = new Window("test");
}
}
I've also tried changing it to:
label = new JLabel(imgIcon);
but that didn't work either
On a different note, what does the line "setLocationByPlatform" do?