How to display bold text in only parts of JTextArea?
how to display text in jtextarea in java
jtextarea format text
swing jtextarea font
jtextarea text color
how to change font size in textarea java
Can I alter the text of a
JTextArea to bold (append text) and then back to normal and will it only display the bold text in bold and the rest as normal?
Also can the contents of
JTextArea be saved as an RTF document?
No. What you're looking for is JEditorPane
This supports HTML (3.2?) which will allow you to use
<font> (and other older tags) to provide rich text.
JEditorPane textarea = new JEditorPane("text/html", ""); textarea.setText("Here is some <b>bold text</b>");
EDIT: According to the javadoc I referenced above, JEditorPane also supports limited RTF. Don't forget to change the MIME to
How to stylize (make bold) text in a JTextArea?, How to stylize (make bold) text in a JTextArea? sb. append("<html><b>Employee Information</b></html>"); The two arguments to the JTextArea constructor are hints as to the number of rows and columns, respectively, that the text area should display. The scroll pane that contains the text area pays attention to these hints when determining how big the scroll pane should be. Without the creation of the scroll pane,
How to display a bold text inside the JTextArea in Java?, We can set a font to a text inside the JTextArea by using setFont() method. Example. import java.awt.*; import javax. Add the button or menu item to the frame. Then the use can click on the button/menu item to bold the text after it has been selected. This is the way most editor work. You can also add an acceleration to the Action to the Action can be invoked just by using the keyboard.
I believe you need a JTextPane or JEditorPane for that.
How to display bold text in only parts of JTextArea?, Can I alter the text of a JTextArea to bold (append text) and then back to normal and will it only display the bold text in bold and the rest as normal? Also can the Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more Is it possible to display bold and non-bold text in a textarea?
JAVA2EVERYONE: Set JTextArea text bold, Set JTextArea text bold. Source code below will show you, how to set JTextArea text to bold. ******* JTextArea is a part of java Swing package . It represents a multi line area that displays text. It is used to edit the text . JTextArea inherits JComponent class. The text in JTextArea can be set to different available fonts and can be appended to new text . A text area can be customized to the need of user . Constructors of JTextArea are:
How to Use Text Areas (The Java™ Tutorials > Creating a GUI With , The JTextArea class provides a component that displays multiple lines of text and For example, although a given text area can display text in only one font and Constructs a new JTextArea with the specified number of rows and columns, and the given model. 4: JTextArea(int rows, int columns) Constructs a new empty TextArea with the specified number of rows and columns. 5: JTextArea(String text) Constructs a new TextArea with the specified text displayed. 6: JTextArea(String text, int rows, int columns)
How to Use Text Areas, The two arguments to the JTextArea constructor are hints as to the number of For example, although a given text area can display text in only one font and To set the font and color of JTextArea we can use the setFont() and setForeground() methods of the JTextArea. To create a font we must define the font name, the font style and its size. For the colors we can uses the constant color values defined by the Color class.
- I would use a JTextPane. It is easier to work with than trying to format and manipulate HTML. Click on the link to the Swing tutorial for a working example.
- thanks. please contribute the link. :)
- how would you go about appending text to JEditorPane? setText? getText?
- @ikurtz Yep,
setText(getText() + "...");
- sorry but this does not work. as multiple <html></html> tags are introduced so only the first occurance is displayed and rest of the data ignored.
- Welcome to Stack Overflow! While this code could solve the problem, it is best to add elaboration and explain how it works for people who might not understand this piece of code.