0

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);
    }
}
Attachments test.png 13.36 KB
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by peter_budo
0

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

Thanx for spotting

Flashing red face, hiding in the corner :$

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.