Hello,
I'm trying to add an Image to my JPanel, but I'm not sure how to add it. I know there are lots of thread like this available, but for me I can't get it working.
I found that for adding picture I can use Canvas. Can you pls help me and show me what I'm doing wrong?
here is the code ....
Maps = new JPanel(); mainTab.addTab("Maps", null, Maps, null); Gcanava canvas = new Gcanava(); Maps.add(canvas);
Here the mainTab is a JTabbledPanel and I have a Maps panel on it.
Gcanava is different class where I have the code for adding picture:
class Gcanava extends JComponent{ /** * */ public void paint(Graphics g){ // Graphics2D g2 = (Graphics2D) g; // // Image img = Toolkit.getDefaultToolkit().getImage("pictures/map.jpg"); // g2.drawImage(img, 100, 100,this); // g2.finalize();
Can you please help me.
Thanks