Adding components to JApplet

D

daniel.w.gelder

Hi, I have a problem that i can't find mentioned in the archives here.
I have a JApplet that gets switched around between states and when the
states change I want to show different controls. I can
getContentPane().remove() the controls i don't want and then repaint()
and that works great. But when I getContentPane().add(newControl, 0)
(the 0 is to put it on top) then *sometimes* it shows and sometimes
not, differently across launches even. I can sometimes resize the
applet to make the stuff show, and then it does, but only after a lot
of jiggling the resize box. Different types of controls seem to work
different ways, for example I have a JSplitPane that doesn't show up
without jiggling, but if i put it in a JPanel first it shows up right
away.

It's not a threading issue, I do the work on a click.

Anyone ever heard of this?? Thanks.
 
T

Thomas Weidenfeller

Hi, I have a problem that i can't find mentioned in the archives here.

Oh, it is for sure there.
I have a JApplet that gets switched around between states and when the
states change I want to show different controls.

"Controls" is Windows slang. Commonly these things are called widgets,
and in Java they are also called components.

Regarding your problem: You want a CardLayout.

/Thomas
 
D

daniel.w.gelder

Calling validate() on the applet did the trick real nice. Thank you so
much. I had never heard of that command and don't see it in my java
book.
 
A

Andrew Thompson

Calling validate() on the applet did the trick real nice. ...
I had never heard of that command ..

Aaah.. that is where the JavaDocs become very handy.

The downloadable version is much better, but they
can also be browsed online. Here is the 'Overview'
page of the JavaDocs.
<http://java.sun.com/j2se/1.5.0/docs/api/overview-summary.html>
(click the link to the 'frames' version if you feel
brave and have very 'broad'band - they are huge!)

Note that if you 'search' down through the methods
of the Docs for JApplet*, you will see 'validate'.
..don't see it in my java book.

Books are great (try reading the JavaDocs on a train,
or at the bus stop!), but they can only take you so
far. Time to *bookmark* the JavaDocs, no?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,127
Latest member
CyberDefense
Top