Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Removal & subsequent addition of GUI components on Applet

  Asked By: Leona    Date: Jun 29    Category: Java    Views: 1308
  

Consider the following code:

import ......
......

public class sample extends Applet
{

public void init()
{
//initialize variables
add(yes);//.....GUI components
add(no);//.....GUI components
//yes & no are checkboxes in a group

}

public void removecomponents()
{
//this method removes the GUI components
//previously added
//by the init() method

}

public void displaycomponents()
{
//initialize other variables
Graphics dg=getGraphics();
add....//other components
add....//other components

}


public void itemStateChanged(ItemEvent ie)
{
//Here I have written code that checks which
//checkbox is selected, then executes further
//code accordingly

displaycomponents();
//When this method is called the Applet should
//display the newly added components
//However the applet displays the newly added
//components only after minimizing & maximizing
//it.
}

What can be done to make the applet display the newly
added components immediately?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Edfu Massri     Answered On: Jun 29

After adding/removing the components  we have to call
validate() of the applet  class. This will cause applet
container to lay out its subcomponents again after the
components it contains have been added  to or modified.

 
Didn't find what you were looking for? Find more on Removal & subsequent addition of GUI components on Applet Or get search suggestion and latest updates.




Tagged: