• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTextComponent: Making certain text within the component as Bold

 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the Swing forum for expert attention.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic