Java - Text format to change

194 Views Asked by At

Like in word I want to change the text color in my project here's the code I made

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.JFrame;

public class Cool extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField textField;

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Cool frame = new Cool();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
 }

 public Cool() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);
    setTitle("JNotePad");

    textField = new JTextField();
    contentPane.add(textField, BorderLayout.NORTH);
    textField.setColumns(30);

    JScrollPane scrollPane = new JScrollPane();
    contentPane.add(scrollPane, BorderLayout.CENTER);

    JTextArea IAmText = new JTextArea();
    IAmText.setRows(10);
    IAmText.setColumns(30);
    scrollPane.setViewportView(IAmText);



    pack();
 }
 }

what can i use please explain. I will be very grateful. Please!!! I have added all i knew can any body give a newer fresher idea like I dont know fresher and better idea that can improve this and can anybody help me with text wrap.I want that when the text reaches the end of the window it would automatically get to the next line so that i dont have to worry about it going all the way to up to a hundred and twenty miles and the person scrolls and scrolls.

1

There are 1 best solutions below

0
On

I mean for example some one wants to write one thing red or either in a different format so what would i use

You have already been given the answer. You need to use a JTextPane or JEditorPane. I find using the JTextPane is easier.

Read the section from the Swing tutorial on Text Component Features for more information and working examples.