Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help need! about JButton  RSS feed

 
Calanthe Wei
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all
I want to add two line text under each icon on a JButton in the toolsbar. How can I do that? Right now, I can only add these words in one line under the icon of the button.
Thank you in advance.
Calanthe
 
Sean Casey
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to make it two lines instead of one, add a "\n" to the end of each string.
String a = "This goes under\n"+
" a button";
This would display the text on two lines instead of 1 by using the "\n".
 
Calanthe Wei
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried this way, but it doesn't work.It will show some other sign other than a new line.
Can anyone give me more idea? Thank you!
Calanthe
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Calanthe,
To get multi-lined labels or buttons you will need to use html code. The following will work:
"<html>First line<p>Second line</html>"
The case must be lower or else the component won't interpret the html correctly.
Regards,
Manfred.
 
Calanthe Wei
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great, It works this way. Thank you so much,guys!
Calanthe
 
Calanthe Wei
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just one more question, How can I change the font face in that html line? I find the font face on that text cannot be change even though I add
"<html> <font face = morden> try</font></html>"
Can anyone will me some idea? Thank you in advance!
Calanthe
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm no font expert, but have you checked out the information in Working with Text and Fonts from Sun's Java Tutorial?
Good Luck,
-Dirk Schreckmann
[ March 11, 2002: Message edited by: Dirk Schreckmann ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!