Article View: comp.lang.java.programmer
Article #268Re: simple applet (code included) won't redraw properly
From: Real Gagnon
Date: Mon, 08 Dec 1997 00:00
Date: Mon, 08 Dec 1997 00:00
56 lines
2325 bytes
2325 bytes
Geoff_Ingram@ml.com a οΏ½crit:
>
> I had a problem with redrawing the screen in an applet. I have reproduced
> the problem using a simple applet that consists of a Choice list
> containing "A", "B", "C". When you select from the list, a grid is drawn
> below it, containing the letter you selected, replacing any previous grid
> that existed. JDK 1.1 AWT is used.
>
> I cant get the grid to display properly from my code when I select from
> the Choice list. Under Netscape 4.0.4 with JDK 1.1 update it displays
> properly if I press Reload button on browser. Under appletviewer it
> displays properly only if I resize the screen. Under IE4 plus SDK 2.0
> update it never displays properly.
>
Hi Geoff,
Maybe you got an answer about your problem... Anyway here a corrected
displayGrid method, tested with the Appletviewer and N4.
public void displayGrid(String s)
{
int dim=1;
if (s.equals("A"))
dim=5;
else if (s.equals("B"))
dim=4;
else if (s.equals("C"))
dim=3;
GridLayout grid = new GridLayout(dim,dim);
if (pnl_grid != null) {
remove(pnl_grid);
// ** ADDED **
invalidate();
}
pnl_grid = new Panel();
pnl_grid.setLayout(grid);
for (int row=0;row<dim;row++)
for (int col=0;col<dim;col++)
{
pnl_grid.add(new Label(s));
}
gridbag.setConstraints(pnl_grid,constr);
add(pnl_grid);
// ** ADDED **
validate();
// ** ADDED **
repaint();
}
Good Luck.
--
Real Gagnon mailto:gagnonr@gespro.com
JAVA & Javascript How-to
http://www.geocities.com/SiliconValley/Vista/1337
Technical Details
Message-ID:
<348CB9CC.CD83C7E2@gespro.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<880983591.6943@dejanews.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10a146,7336280b6ba26964 X-Google-Attributes: gid10a146,public X-Google-Thread: 100145,7336280b6ba26964 X-Google-Attributes: gid100145,public X-Google-Thread: ff01d,7336280b6ba26964 X-Google-Attributes: gidff01d,public From: Real Gagnon <gagnonr@gespro.com> Subject: Re: simple applet (code included) won't redraw properly Date: 1997/12/08 Message-ID: <348CB9CC.CD83C7E2@gespro.com> X-Deja-AN: 296475273 References: <880983591.6943@dejanews.com> To: Geoff_Ingram@ml.com Organization: Gespro Informatique inc. Reply-To: gagnonr@gespro.com Newsgroups: comp.lang.java.programmer,microsoft.public.java.visualj++,borland.public.jbuilder.applet-issues