java - JLabel - how to hide a text? -
i have jlabel icon , text. there possibility hide jlabel's text? don't want hide whole component (setvisible(false)), text, icon remains visible. i'd still use gettext , settext methods.
thanks help!
as far i'm concerned, there's no direct way this. try of following:
- extend jlabel , override settext() , gettext() methods. these should store text give in new string field. every time call settext should delegate super.settext() label-text not invisible. add method switches visibility. if call settextvisibility() true, class should call super.settext() string of spaces.
here's example of mean:
public class mylabel extends jlabel { private string labeltext; private boolean labeltextvisible = true; private mylabel( string text, icon icon, int horizontalalignment ) { super( text, icon, horizontalalignment ); labeltext = text; } private mylabel( string text, int horizontalalignment ) { super( text, horizontalalignment ); labeltext = text; } private mylabel( string text ) { super( text ); labeltext = text; } @override public void settext( string text ) { if ( labeltextvisible ) { super.settext( text ); } labeltext = text; } @override public string gettext() { return labeltext; } public void setlabeltextvisible( boolean labelvisible ){ if(labelvisible){ if(!labeltext.equals( super.gettext() )){ super.settext( labeltext ); } }else{ int spacecount = super.gettext().length(); string hiddentext = ""; ( int = 0; < spacecount; i++ ) { hiddentext+=" "; } super.settext(hiddentext); } this.labeltextvisible = labelvisible; } public boolean getlabeltextvisible(){ return labeltextvisible; } } - (this more of hack, work) make foregroundcolor of label match background color text no longer visible.
Comments
Post a Comment