Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

java.awt question

  • 29-09-2001 12:11pm
    #1
    Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭


    How do you paint an Image over a Panel? I'm trying to display an image on a panel but the image is drawn behind the panel not in front of it. :mad:

    Any idea's?


Comments

  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    I am assuming that you are adding that Panel to a Frame and the image is being drawn on the Frame (behind the Panel), yeah?

    Right, this is what I would do,

    Create a new class that inherits from java.awt.Panel . Override it's paint method, with something like this
    public void paint(Graphics g){
            Image img = Toolkit.getDefaultToolkit().getImage(file_string);        
            g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
    }
    

    Then simply add this Panel to your Frame. The kewl thing about this is if, your Panel get's resized the image will scale accordingly.

    ;-phobos-)


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    or if you don't need a whole class for the panel, you can just get it's graphics context and draw to that, like this:
    Panel p=new Panel();
    Graphics g=p.getGraphics();
    g.drawImage(....);
    

    Panels can be a bit strange so I'm not 100% sure if this works, but it should.


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    Yes that would work alright.

    Why do I always think that ppl will want to make several instance of something. Bad phobos, BAD!!

    ;-phobos-)


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Neither of thos are working for me, but they look sound. I'll review my code and let you know.

    thanks


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    try adding a Canvas to the panel and then draw to the canvas (the same way as above).


  • Advertisement
Advertisement