can't stop JPanel paint

Discussion in 'Java' started by Peter Cheung, Jul 14, 2011.

  1. Peter Cheung

    Peter Cheung Guest

    Hi
    I have overrider all the paintXX method and did nothing in there. But why I still able to see the component on top of the JPanel?

    thanks
    from Peter ()

    import java.awt.CardLayout;

    public class Carousel extends JPanel {
    public Carousel() {
    setLayout(new CardLayout(0, 0));
    b.setSize(100, 100);
    }

    public Component add(Component c) {
    add(c, "");
    return c;
    }

    public void paint(Graphics g) {
    }

    public void paintComponents(Graphics g) {

    }

    public void paintChildren(Graphics g) {
    System.out.println("ss");
    }

    public void paintImmediately(int x, int y, int w, int h) {
    }

    public void paintImmediately(Rectangle r) {
    }

    public void repaint(long tm, int x, int y, int width, int height) {

    }
    }
    Peter Cheung, Jul 14, 2011
    #1
    1. Advertising

  2. On 14/07/2011 7:43 AM, Peter Cheung wrote:
    > Hi
    > I have overrider all the paintXX method and did nothing in there. But why I still able to see the component on top of the JPanel?


    A component in a container such as a panel paints itself separately, not
    as part of the panel's paint. If the area is obscured and then
    uncovered, a repaint event is sent to the panel first, then to its
    children. Even if the panel itself ignores the event the children
    generally won't.
    supercalifragilisticexpialadiamaticonormalizeringe, Jul 14, 2011
    #2
    1. Advertising

  3. Peter Cheung

    Roedy Green Guest

    On Thu, 14 Jul 2011 04:43:04 -0700 (PDT), Peter Cheung
    <> wrote, quoted or indirectly quoted someone who said
    :

    >Hi
    > I have overrider all the paintXX method and did nothing in there. But why I still able to see the component on top of the JPanel?


    you would gave to block the paint methods of all the children which
    might be invoked independently of the JPanel container if their values
    changed.

    I trust you are just experimenting. The proper way to hide things is
    with setVisible( false ).
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    Most of computer code is for telling the computer
    what do if some very particular thing goes wrong.
    Roedy Green, Jul 26, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Beresko

    Add a JPanel to a JPanel...

    Andreas Beresko, Jul 14, 2004, in forum: Java
    Replies:
    6
    Views:
    26,976
  2. Rajesh.Rapaka

    paint my jpanel

    Rajesh.Rapaka, Apr 22, 2005, in forum: Java
    Replies:
    1
    Views:
    4,515
    Thomas Weidenfeller
    Apr 22, 2005
  3. Replies:
    4
    Views:
    4,616
    Brendan Guild
    Oct 23, 2005
  4. Raphael Jolivet

    [JPanel] Drop Down JPanel

    Raphael Jolivet, Jul 18, 2008, in forum: Java
    Replies:
    1
    Views:
    1,514
    John B. Matthews
    Jul 18, 2008
  5. Aaron Fude
    Replies:
    3
    Views:
    2,672
    Mayeul
    Nov 7, 2008
Loading...

Share This Page