• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextComponent: Making certain text within the component as Bold  RSS feed

 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Readers,
I wanted to know if it is possible to bolden only certain text within any JTextComponent instances. I tried doing it in JTextField and JTextArea but unfortunately it emboldens the entire text.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Swing forum for expert attention.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextField and JTextArea do not support multiple fonts or font properties. For this you can use styled text in a JTextPane. See the introductory page Using Text Components and the page it links to How to Use Editor Panes and Text Panes. JEditorPane is the more complex component.
 
Tal Nathan Tal Nathan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this works with javax.swing.JLabel but not sure what other components, basically you can format it using html.

ie:

lbl.setText("<html>Hello this is<b>bold<b></html>");
 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Readers,
I guess I will be using the Styled Text Components after all. I have been reading from the Sun Tutorial and it's a good feeling that I am getting while exploring the world out of the JTextField and JTextArea. It seems so interesting.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!