wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes How do you Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How do you "delete" a JLabel before adding a JLabel on top?" Watch "How do you "delete" a JLabel before adding a JLabel on top?" New topic
Author

How do you "delete" a JLabel before adding a JLabel on top?

Andrew Brown
Greenhorn

Joined: Apr 10, 2006
Posts: 25
i am writing an aplet that changes certain JLabels that i have created when a button is clicked, when i change the label it simply over writes the old label witht the new, which would be ideal, but i can still see the JLabel text from the previous Label that has been laid down.

Any ideas?


Thanks for any help anyone can offer.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

If you want to change the text in a JLabel, why wouldn't you just call its setText(String) method? Trying to delete a JLabel and then add a new one in the same place strikes me as being the hard way to do things.
Andrew Brown
Greenhorn

Joined: Apr 10, 2006
Posts: 25
again i have the same problem. At the moment i have a JLabel(na), where na is a string and i change the string and print it out over the top using updateUI(), but i can still see the text that was there previous, and i don't want to be able to.

When i changed the text using the suggested setText(); method, it had the same effect.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> When i changed the text using the suggested setText(); method, it had the same effect.

your applet could be using a cached .class file i.e. not using the updated file

copy the .java file into another directory, recompile and run it again.
Andrew Brown
Greenhorn

Joined: Apr 10, 2006
Posts: 25
This is not the case as i have recompilerd it in a different directory and it still writes the letters over the top, leaving me with nothig but giberish.

I have also tried calling the back ground to be white so that it is still there but you simply can't see it, but this did not work either.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
probably get your problem solved a lot quicker if you post the code you are using
Andrew Brown
Greenhorn

Joined: Apr 10, 2006
Posts: 25
nb = "null";

bNotesCanvas = new JLabel(nb);

then a separate method saying:

if(event.getSource() == convertButton){
refresh();
}

refresh being:

public void refresh(){
nb = "a";
bNotesCanvas.updateUI();
}

Sorry, didn't think about that.
Jared Cope
Ranch Hand

Joined: Aug 18, 2004
Posts: 243
Originally posted by Andrew Brown:
nb = "null";

bNotesCanvas = new JLabel(nb);
...
...
public void refresh(){
nb = "a";
bNotesCanvas.updateUI();
}



Hi,

I would change the line

with


I don't think changing the value of (what I assume is a String variable) nb propagates to the JLabel (even though you have passed that into the constructor). I believe the constructor will use nb as a 'value' rather than a 'reference'.

Cheers, Jared.


SCJP 1.4 91%, SCJP 1.5 88%, SCJD B&S
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you "delete" a JLabel before adding a JLabel on top?
 
Similar Threads
how to Implement array of Components?
How do we add JLabel with leading Icon into JTable Cell
Error on trying to add JLabel in a cell of JTable
Display arrow button over label icon on focus
unicode char display