• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doLayout()

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if you add the TextField to the panel when you init() rather than in actionPerformed but keep it hidden. Then when you press the button, unhide (setVisible(true)) it.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
raymond yadao
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your replies guys!!!
one thing more, what's the difference of doLayout() and validate() method?
thanks in advance!!!
raymond
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

public void doLayout()
Causes this container to lay out its components. Most programs should not call this method directly, but should invoke the validate method instead.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic