jlabel

Is there a “word wrap” property for JLabel?

北城以北 提交于 2019-11-26 00:26:15
问题 I am displaying some text in a JLabel. Basically I am generating that text dynamically, and then I apply some HTML tags (e.g., BR and B ) to format the text. Finally I assign this formatted text to my JLabel. Now I want my Jlabel to automatically wrap the text to the next line when it reaches the end of screen, like the \"Word Wrap\" feature in Note Pad. How can I do that? 回答1: Should work if you wrap the text in <html>...</html> UPDATE: You should probably set maximum size, too, then. 回答2: A

Update JLabel repeatedly with results of long running task

非 Y 不嫁゛ 提交于 2019-11-25 22:58:56
I'm writing a program that constantly pings a server. I wrote the code to check it once and put the ping in a JLabel and put it in a method called setPing() . Here is my code private void formWindowOpened(java.awt.event.WindowEvent evt) { setPing(); } That worked but only did it once, so I did: private void formWindowOpened(java.awt.event.WindowEvent evt) { for(;;){ setPing(); } } But this doesn't even work for the first time. I didnt put the setPing method because it was too long so here it is: public String setPing(){ Runtime runtime = Runtime.getRuntime(); try{ Process process = runtime