Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Font in JTextComponent  RSS feed

 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Readers,
How to change the font of selected text in JTextArea or JTextField? I tried by getting the selected text but when I apply the font the whole of the area gets affected.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Using Text Components for a summary of what these components can do. Then check out the 'Using an Editor Pane to Display Text from a URL' section on the How to Use Editor Panes and Text Panes page. Most of the example code has been removed but you can stiil download the 'TextSamplerDemo.java' file which has an example of how to do this with a JTextPane and StyledDocument.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!