1 Attachment(s)
Can't paint my Buffered image on my component?
Hey,
I was trying to create a component that displays an image from my Computer in Netbeans IDE.
but the image never displays.. I'm sure it gets loaded right. (confirmed with try/catch and println)
the red circle I draw on the component is visible so the component is added right ;)
anyone knows what I did wrong?
Component code:
Code:
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
public class Fieldcomponent extends JPanel {
LoadImage Tiles = null;
public Fieldcomponent() {
Tiles = new LoadImage("Tiles.png");
}
@Override
public void paintComponent(Graphics g) {
int w = getWidth();
int h = getHeight();
g.setColor(Color.red);
g.drawOval(0, 0, 20, 20);
g.drawImage(Tiles.getImage(),w,h, null);
}
}
output:
Attachment 3851
Re: Can't paint my Buffered image on my component?
You're drawing your image to the right and below the JPanel; read the API documentation for the drawImg( ... ) methods in the Graphics class.
kind regards,
Jos
Re: Can't paint my Buffered image on my component?
Oh wow can't believe i did somthing so stupid :x:
Thanks very much its working now =D