java - How to use HTML in Swing -


i have bit of unusual problem: have swing label updates "used letters" in game hangman. have declared this:

used = new jlabel(" used: "); 

but have area in code add onto it. here:

used.settext(used.gettext() + lused  + " , "); 

now when user enters letters, updates label , letters added, if enter enough, push rest of contents of frame out of view. label expands west side of borderlayout else get's pushed , times cut off application window.

is there way use html make word wraps text , not change panel (what it's contained in) size?

    gridlayout c = new gridlayout(rows,0);     westpanel = new jpanel(c);     westpanel.add(guessedpanel);     westpanel.add(usedpanel);     frame.getcontentpane().add(westpanel, borderlayout.west); 

how it's laid out ^^

for more general solution coming google, can add html swing components easily, long content being added starts , ends proper html tags.

for example, may insert html text jlabel such that:

label.settext("<html> text </html>"); 

you color center , underline first letter this:

label.settext("<html><center><u>t</u>ext</center></html>"); 

here's good tutorial on how use html in swing components.

--

for specific solution, can use html when adding text label. instead of using used.gettext() should store text in string somewhere (that not enclose opening , closing html tags), , update string, in order able manage opening , closing html tags. go this

string text; // earlier in code ... text += ("<br> " + lused); used.settext("<html>" + text + "</html>") 

among other things, attempt setting preferred or maximum size of label not allowed become large. also, make label text panel or text area of kind instead, automatically support word wrapping, scrolling, , other features may want.

here's guide on how use jtextareas.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

methods - python can't use function in submodule -

c# - ErrorThe type or namespace name 'AxWMPLib' could not be found (are you missing a using directive or an assembly reference?) -