Hi all,
Can anyone tell me why my image doesn't appear in my frame's container? When I change imageIcon to just normal Label, it does go work.
In another condition, if i don't use method return (what is it called? emm...). ImageIcon does work on my normal Label.
Thanks for any advice...
Can anyone tell me why my image doesn't appear in my frame's container? When I change imageIcon to just normal Label, it does go work.
In another condition, if i don't use method return (what is it called? emm...). ImageIcon does work on my normal Label.
Code:
package practise; import java.awt.*; import javax.swing.*; public class layout_test { public Container createContentPane() { JPanel contentPane = new JPanel(new BorderLayout()); contentPane.setOpaque(true); contentPane.add(createNorthPanel(), BorderLayout.NORTH); contentPane.add(createCenterPanel(), BorderLayout.CENTER); return contentPane; } public JPanel createCenterPanel() { JPanel centerPanel = new JPanel(); JLabel image = new JLabel(new ImageIcon("Bovinetine.jpg")); // Image doesn't appear centerPanel.add(image); return centerPanel; } public JPanel createNorthPanel() { JPanel northPanel = new JPanel(new GridLayout(1,3)); JButton b1 = new JButton("b1"), b2 = new JButton("b2"), b3 = new JButton("b3"); northPanel.add(b1); northPanel.add(b2); northPanel.add(b3); return northPanel; } public static void main(String[] args) { JFrame frame = new JFrame("Testing Layout with Image"); layout_test layout = new layout_test(); frame.setContentPane(layout.createContentPane()); frame.pack(); frame.setVisible(true); } }
Comment