Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

paintComponent not being called on my glasspane

843805Dec 9 2005 — edited Dec 10 2005
here is some code for a glasspane that I have.
For some reason, it never hits the paintComponent.

My program does:
public class GlassPane extends JPanel {
    
    /** Creates a new instance of glassPane */
    public GlassPane() {
        
    }
    
    public void cashierAction(JPanel panel, int initialX, int initialY) {
        frame = (JFrame)SwingUtilities.getAncestorOfClass(JFrame.class, panel);
        glass = (JPanel) frame.getGlassPane();
        //glass.setLayout(null);
        
        xPos = initialX;
        yPos = initialY;
        
        glass.setVisible(true);
        
        cashierAnimation = true;
        
        repaint();
        
    }
    
    public void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D)g;
        super.paintComponent(g);

        if(cashierAnimation) {
            g2d.drawImage(this.dollarSign, xPos, yPos, 10, 10, null);
        }
    }
    
    
    private JFrame frame;
    private JPanel glass;
    private int xPos;
    private int yPos;
    private boolean cashierAnimation = false;
    private ImageIcon dollarImg = new ImageIcon("Data/Icons/dollar.gif");
    private Image dollarSign = dollarImg.getImage();
    
}
Any ideas why it is not running the paintComponent?
I am pretty new to glass panes, I have gotten them to work with buttons, and other items, but painting on them is driving me crazy.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 7 2006
Added on Dec 9 2005
2 comments
191 views