Override paintComponent instead of paint

protected void paintComponent(Graphics graphics) {
        super.paintComponent(graphics);
        ---- - - - - - -your code- - - - -- - - - --
}

Unlike awt, Swing factors paint() to 3 sub calls
paintComponent()
paintChildren() and
paintBorder()

when u override paint() of panel, its children may not be painted, unless a recursive call come from the heavy wieght container

pls try.

regards,
Manoj
       




Girish KR <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]

09/03/03 03:32 PM

       
        To:        [EMAIL PROTECTED]
        cc:        
        Subject:        Image not showing



Hi every one
 I am facing a problem that seems bizzare to me.
 
 I have created a wizard which uses the fancy
 
text over image featue on the left to show the current
step

This is handled by the following component called
wizard whose source code is shown below

But it is not showing the image sometimes.

But when i force a repaint say by moving another
window over it, parts of the image start appearing

Can ne one tell me how to solve this problem.

Thanx in advance
Regards
Girish

*/
public class WizardImage extends javax.swing.JPanel
{

   /** Array for steps labels*/
   private String[] steps = new String[0];

   /** image for wizard*/
   private Image image;

   /** Array of labels showing number of steps*/
   private JLabel[] bullets;

   /** Color representing still to come step*/
   private Color stillToComeStepColor = Color.gray;

   /** Color representing completed steps*/
   private Color doneStepColor = Color.black;

   /** Creates a new instance of WizardImage */
   public WizardImage()
   {
       super(false);
       createUI();
   }

   public void paint(Graphics g)
   {
       if (image != null)
       {
           g.drawImage(image, 0, 0, null);          

       }

       super.paint(g);
   }

   /**
    * set image
    * @param image
    */
   public void setImage(Image image)
   {
       this.image = image;
   }

   /**
    * sets steps bullets for wizard
    * @param steps
    */
   public void setSteps(String[] steps)
   {
       this.steps = steps;
       addBullets();
   }

   /** Setter for property doneStepColor.
    * @param doneStepColor New value of property
doneStepColor.
    *
    */
   public void setDoneStepColor(java.awt.Color
doneStepColor)
   {
       this.doneStepColor = doneStepColor;
   }

   /**
    * This is responsible for handling font style of
steps
    * @param index
    */
   public void setActiveStep(int index)
   {
       Font f = bullets[0].getFont();
       f = new Font(f.getName(), Font.PLAIN,
f.getSize());
       JLabel label = null;
       for (int i = 0; i < bullets.length; i++)
       {
           label = bullets[i];
           label.setFont(f);
           if (i < index)
           {
               label.setForeground(doneStepColor);
           }
           else
           {
             
label.setForeground(stillToComeStepColor);
           }
       }

       f = new Font(f.getName(), Font.BOLD,
f.getSize());
       label = bullets[index];
       label.setFont(f);
       label.setForeground(doneStepColor);
   }

   /** Setter for property stillToComeStepColor.
    * @param stillToComeStepColor New value of
property stillToComeStepColor.
    *
    */
   public void setStillToComeStepColor(java.awt.Color
stillToComeStepColor)
   {
       this.stillToComeStepColor =
stillToComeStepColor;
   }

   /**
    * calls setopaque method
    * @param isOpaque
    */
   public void setOpaque(boolean isOpaque)
   {
       super.setOpaque(false);
   }

   /**
    * adds bullets to the steps label showing numbers
of steps
    */
   private void addBullets()
   {
       removeAll();
       bullets = new JLabel[steps.length];
       for (int i = 0; i < bullets.length; i++)
       {
           JLabel step = new JLabel(steps[i]);
         
step.setBorder(BorderFactory.createEmptyBorder(3, 3,
3, 3));
           Font f = step.getFont();
           f = new Font(f.getName(), Font.PLAIN,
f.getSize());
           step.setFont(f);
           step.setOpaque(false);
           step.setForeground(stillToComeStepColor);
           bullets[i] = step;
           add(step);
       }
   }

   /**
    * creates the ui
    */
   public void createUI()
   {
       setBorder(
           BorderFactory.createBevelBorder(
             
javax.swing.border.BevelBorder.LOWERED));
       setLayout(new BoxLayout(this,
BoxLayout.Y_AXIS));

        addBullets();
   }

}


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing



Reply via email to