Results 1 to 4 of 4
  1. #1
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    105
    Rep Power
    0

    Post using paintcomponent to draw over a jbutton

    hello,

    i am trying to draw an image with the graphics object in paintcomponent on top of a jbutton, but the jbutton keeps showing up on top of the image, even when i add the button first then the paint component.

    kind of like

    Java Code:
    public myclass{
    myjbutton = new jbutton();
    myframe.add(myjbutton);
    myframe.add(this);
    }
    public void paintcomponent(g){
    g.drawimage(myimage, 0, 0, this);
    }
    anyone know how to draw images in paintcomponent over jbuttons?

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

    Default Re: using paintcomponent to draw over a jbutton

    The paint( ... ) method does that: it calls the paintComponent( ... ) method and after that it paints the child components of the component to be painted.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,734
    Rep Power
    7

    Default Re: using paintcomponent to draw over a jbutton

    Check out the use of Root Panes. Specifically the glass pane. It should allow you to do what you want.

    How to Use Root Panes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    105
    Rep Power
    0

    Default Re: using paintcomponent to draw over a jbutton

    to jim:

    this was a seperate problem that was resolved by switching "paintComponent" to "paint"

Similar Threads

  1. JButton User Draw Text?
    By tim8w in forum AWT / Swing
    Replies: 1
    Last Post: 01-21-2013, 09:16 AM
  2. Replies: 1
    Last Post: 01-15-2013, 07:44 PM
  3. ActionListener for JButton after changing Button to JButton
    By ravi.joshi53 in forum Java Applets
    Replies: 2
    Last Post: 10-07-2011, 07:35 AM
  4. Help with paintComponent!
    By joeyea in forum Java 2D
    Replies: 6
    Last Post: 12-27-2010, 02:59 PM
  5. Replies: 7
    Last Post: 04-14-2009, 07:12 PM

Tags for this Thread

Posting Permissions

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