What are the syntax for Bolding text in a JTextArea . I know that JTextArea do not word wrap when ever you type the text in it and it's multi-line area that displays plain text. What is difference between JTextPane and JTextArea.
What are the syntax for Bolding text in a JTextArea . I know that JTextArea do not word wrap when ever you type the text in it and it's multi-line area that displays plain text. What is difference between JTextPane and JTextArea.
You are wrong in saying that JTextArea does not support word wrapping. javax.swing.JTextPane class represents a significant improvement over AWT’s TextArea. JTextArea is different in that it doesn't manage scrolling, but implements the swing Scrollable interface.Using the methods setLineWrap(..) and setWrapStyleWord(..) you can control whether you want word wrap and in what manner you want to do it.
Code:import javax.swing.JTextArea; import javax.swing.JFrame; import java.awt.BorderLayout; import java.awt.Font; public class bold { public static void main(String[]args) { //Create text area using JTextArea JTextArea Area=new JTextArea(); //Set line wrap to true Area.setLineWrap(true); Font AreaFont=new Font(Area.getFont().getName(),Font.BOLD,Area.getFont().getSize()); Area.setFont(AreaFont); JFra frame=new JFra("Set text bold"); frame.setLayout(new BorderLayout()); frame.add(textArea); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500,600); frame.setVisible(true); }
textArea.setForeground(Color.blue); changes the color or you can use
Code:Font font = new Font("Verdana", Font.BOLD, 12); JVtxt.setFont(font); JVtxt.setForeground(Color.BLUE);
Bookmarks