scenario: i have a program that (at first) has two components: two buttons (labeled text and button); i used a borderlayout and these components are position at the NORTH. what i would like to do is as a click the text button, a textfield will show from the center (BordeLayout.CENTER) same as i click the button button a button will replace the textfield form the center.i have here my code: //<applet code=formSelector height=300 width=300> //</applet>
i compiled and it run but as i click the button it displays nothing.
thanks in advance..... raymond [ January 28, 2002: Message edited by: Cindy Glass ]
I'm also curious about how to add components to an applet after it has been initiated and about how to cause hidden components to become visible. I would have thought that the following code would accomplish this second task, but it does not.
This code demonstrates the order of automatic method calls that add components: first the constructor, then init(), then start() - are there any others that can add components? How would it be accomplished to cause a hidden component to become visible? Thank You [ January 28, 2002: Message edited by: Dirk Schreckmann ]
Hi Dirk, First off you need to add your class as a ActionListener for all the buttons in order for the actionPerformed method to be called at all. Second, you need to understand how layoutManagers work. Calling repaint does not perform any layout managing it justs invokes redraw on all its know children depending on the clipping rectangle specified inside the Graphics component. If you happen to look at the Container API you will see a method called validate. What it is for is to perform the layout whenever something has changed (i.e., window resize, component shown/hidden, etc.). That seems to be what you want. Your program will work correctly if you just replace your call to repaint with a call to validate at the bottom of your actionPerformed method. Regards, Manfred.
Joined: Dec 10, 2001
Hello, Here is the corrected code (with the components registered as action listeners -- must have been tired last night when first posted):
Thanks again Manfred.
Joined: Jan 29, 2001
thanks for your replies guys!!! one thing more, what's the difference of doLayout() and validate() method? thanks in advance!!! raymond