Hi there,
In the code below my ImageIcon isn't showing when I run the program. I always struggle with adding Images in my GUIs and it's irritating. Is there some all important rule that I should know or something?
//Create window Components
JLabel lblrequest = new JLabel("Enter amount of square meters:");
JTextField inpt = new JTextField(10);
JButton btnEnter = new JButton("Enter");
JButton btnClear = new JButton("Clear");
JLabel lblAdhesive = new JLabel("Adhesive:");
JLabel AdhOutput = new JLabel("0 X 20kg bags.");
JLabel lblGrout = new JLabel("Grout:");
JLabel GrtOutput5 = new JLabel("0 X 5kg bags.");
JLabel GrtOutput20 = new JLabel("0 X 20kg bags.");
ImageIcon image = new ImageIcon("NationalTile.png");
public Container createContentPane(){
//Add window Components
JPanel imagePanel = new JPanel();
imagePanel.setLayout(new FlowLayout());
JLabel imgLabel = new JLabel(image);
imagePanel.add(imgLabel);
JPanel topPanel = new JPanel();
topPanel.setLayout(new FlowLayout());
topPanel.add(lblrequest);
JPanel textPanel = new JPanel();
textPanel.add(inpt);
JPanel btnPanel = new JPanel();
btnPanel.add(btnEnter);
btnEnter.addActionListener(this);
btnPanel.add(btnClear);
btnClear.addActionListener(this);
JPanel AdhesivePanel1 = new JPanel();
AdhesivePanel1.setLayout(new FlowLayout());
AdhesivePanel1.add(lblAdhesive);
JPanel AdhesivePanel2 = new JPanel();
AdhesivePanel2.add(AdhOutput);
JPanel GroutPanel1 = new JPanel();
GroutPanel1.setLayout(new FlowLayout());
GroutPanel1.add(lblGrout);
JPanel GroutPanel2 = new JPanel();
GroutPanel2.add(GrtOutput5);
JPanel GroutPanel3 = new JPanel();
GroutPanel3.add(GrtOutput20);
//Add panels to Container
Container c = getContentPane();
c.setLayout(new GridLayout(10,1));
c.add(imagePanel);
c.add(topPanel);
c.add(textPanel);
c.add(btnPanel);
c.add(AdhesivePanel1);
c.add(AdhesivePanel2);
c.add(GroutPanel1);
c.add(GroutPanel2);
c.add(GroutPanel3);
return c;
}
Thanks for taking a look at this!
*Just let me know if you want to see the rest of the code, sure it won't be needed though..