where am I supposed to add the revalidate or repaint in this class?
thanksCode:import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JComponent; import javax.swing.Timer; /** * @author ad */ public class ScrollingTextComponent extends JComponent implements ActionListener{ private String[] text; private Timer t; int start = 80; private boolean firstTime = true; /** * Create a new Scrolling Text Component * Either Up for Left. */ public ScrollingTextComponent(String[] text) { this.text = text; this.t = new Timer(20, this); this.t.start(); } /** * paint * @see javax.swing.JComponent#paint(java.awt.Graphics) */ public void paint(Graphics g) { if(this.firstTime) { this.start = g.getClipBounds().height; this.firstTime = false; } FontMetrics fm = g.getFontMetrics(); int yLocation = this.start + fm.getHeight(); int stopCount = 0; for(int i = 0; i < this.text.length; i++) { if(yLocation > 0) { g.drawString(this.text[i], 0, yLocation); }else { stopCount++; } yLocation += + fm.getHeight(); } //g.drawImage(this.image, 0, y, null); if(stopCount == this.text.length){ this.start = g.getClipBounds().height; } this.start--; } /** * actionPerformed * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ public void actionPerformed(ActionEvent e) { /** * Force a Repaint. */ this.repaint(); } }
Edit: Fixed! I had to add a revalidate there:
I finally made it thanks for your help!Code:public void actionPerformed(ActionEvent e) { /** * Force a Repaint. */ this.repaint(); this.revalidate(); }




Reply With Quote