Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

why is the component not shown

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my code is
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
//<applet code = "addcomp.class" width=400 height=400></applet>
public class addcomp extends Applet
{
Button b;
public void init()
{
b = new Button("click to add a label");
b.addActionListener(this);
add(b);
}

public void actionPerformed(ActionEvent e)
{
add(new Label("mylabel"));
}
}
my problem is whenever i click the button the label which is added is not immediateley shown on the applet. i have to manually resize or iconify the applet after which the label becomes visible on the applet. I tried calling the repaint() method manually after inside the actionPerformed() method but to no vail.
How can i acheive this
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call the validate() method instead of the repaint() method. Repaint just paints the screen. Validate tells the layout manager to re-configure the layout( which you'll have to do if you are adding a new component on-the-fly... ).

-Nate
 
Forget Steve. Look at this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic