Results 1 to 3 of 3
  1. #1
    Bram is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Question 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:
    Java 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:
    Can't paint my Buffered image on my component?-knipsel.png

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,725
    Blog Entries
    7
    Rep Power
    21

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Bram is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Re: Can't paint my Buffered image on my component?

    Oh wow can't believe i did somthing so stupid
    Thanks very much its working now =D

Similar Threads

  1. Replies: 1
    Last Post: 05-20-2011, 02:59 PM
  2. Volatile image vs buffered image
    By trishtren in forum Java 2D
    Replies: 0
    Last Post: 04-18-2011, 12:31 AM
  3. Replies: 10
    Last Post: 04-11-2011, 10:34 PM
  4. Rotating Buffered Image distorts image
    By VortexSpin in forum Java 2D
    Replies: 1
    Last Post: 02-13-2011, 06:54 AM
  5. Custom component and paint outside of bounds
    By happy_hippie in forum AWT / Swing
    Replies: 2
    Last Post: 06-30-2010, 06:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •