I'm having small issue with drawing on panel. Neither image or text appears, however background is set correctly therefore it has to be due some issue inside my paintComponent() method.

import java.awt.Graphics;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO ;
import javax.swing.JPanel;

public class RottrThumbnailsPanel extends JPanel{

    RottrThumbnailsPanel(){
        init();
        setBackground(Color.BLUE);
        setSize(new Dimension(400,400));
        this.setVisible(true);
    }

    private void init(){
        repaint();
    }

    public void painComponent(Graphics g){
        super.paintComponent(g);
        BufferedImage img = null;
        try{
            img = ImageIO.read(new File("/pdfrotator/res/img/open_green.png"));
        }
        catch(IOException ioe){
            ioe.printStackTrace();
        }
        g.drawImage(img, 100, 100, 50, 50, Color.WHITE, this);
        g.setColor(Color.BLACK);
        g.drawString("Hello Peter", 0,200);
    }
}

Typo in line 24?

public void painComponent(Graphics g)
commented: Well spotted, thank you +19

Yeah you right, missing "t". What a pain :@

Thanx for spotting

Flashing red face, hiding in the corner :$

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.