Home arrow static arrow Java Programming [Archive] - repaint problem
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - repaint problem
This topic has 3 replies on 1 page.

Posts:6
Registered: 7/29/04
repaint problem  
Aug 2, 2004 10:08 AM



 
i have a bit code shown below i enter a search in field and a set of lresults appear but when i enter a new search the old results remains there along with new results can someone help

i suspect its because i using a gridlayout but not sure can someone confirm ? if it is a gridlayout problem how else can i display a set of results one below each other

		public void init() {          		 panel = new Panel(new GridLayout(2,1));				 panel2 = new Panel(new GridLayout(1000000,1));				 panel.add( searchTextField);				 panel.add( searchButton );				 add(panel);				 add(panel2);					}				public boolean action(Event e, Object arg) {			if (e.target instanceof Button)			repaint();			displayResults();			repaint();			return true;		}				   		public void displayResults()		{		try{		while (rs.next())		{   			      			                        Url = rs.getString("Url"); 		Label label2 = new Label(Url);    		panel2.add(label2);    		label2.setForeground(Color.green);		label1.addMouseListener(new Opener(Url));		validate();		repaint();			 }   					}catch (Exception e){System.out.println(e.getMessage());}				} 
 

Posts:19,725
Registered: 9/26/01
Re: repaint problem  
Aug 2, 2004 10:18 AM (reply 1 of 3)



 
You keep adding more labels to your panel, rather than replacing said labels to contain the results you want. Did you think that adding more labels would magically make the old ones disappear?
 

Posts:6
Registered: 7/29/04
Re: repaint problem  
Aug 3, 2004 7:05 AM (reply 2 of 3)



 
ahhh good point

i found out that you could do a panel.removeAll() so i just done panel2.removeAll() and that worked

thank for finding out my stupid error :-)

out of interest how would you replace said labels to contain the results you want ?
 

Posts:19,725
Registered: 9/26/01
Re: repaint problem  
Aug 3, 2004 7:08 AM (reply 3 of 3)



 
out of interest how would you replace said labels to
contain the results you want ?

someExistingLabel.setText(newValue);
 
This topic has 3 replies on 1 page.