Can you change the color of "one line of the JTextArea"?

0

Query, can you change the color of a single line that is printed in a JTextArea? I say, because I'm using JTextArea.setForeground (Color.green) and I change the color of all the lines, my idea is that the one that is correct prints it in green, and the incorrect one in red. I've been doing it, but when it goes into execution I change the color of all the lines.

botonvel1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {

        Object obj= e.getSource();
        if(obj.equals(botonvel1))
        { 
            if(Integer.parseInt(textfieldvel1.getText())<=250)
            {
            System.out.println("bien");
            enunciado.setForeground(Color.green);
            enunciado.append("\n- Velocidad mínima correcta - Esa velocidad puede andar dependiendo de los grados de elevación.\n");
            }
            else{System.out.println("mal");
            enunciado.setForeground(Color.red);
            enunciado.append("- Velocidad mínima incorrecta - Esa velocidad es muy alta para ser mínima.\n");
            }
        }

    }});

botonvel2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {

        Object obj= e.getSource();
        if(obj.equals(botonvel2))
        { 
            if(Integer.parseInt(textfieldvel2.getText())<=450)
            {
            System.out.println("bien");
            enunciado.setForeground(Color.green);
            enunciado.append("\n- Velocidad máxima correcta - A esa velocidad probablemente no se dañen los trenes de aterrizaje.\n");
            }
            else{System.out.println("mal");
            enunciado.setForeground(Color.red);
            enunciado.append("- Velocidad máxima incorrecta - Seguramente los trenes no soporten las abraciones del viento.\n");
            }
        }

    }});


botondist1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {

        Object obj= e.getSource();
        if(obj.equals(botondist1))
        { 
            if(Integer.parseInt(textfielddist1.getText())>=2000)
            {
            System.out.println("bien");
            enunciado.setForeground(Color.green);
            enunciado.append("\n- Distancia mínima correcta - Esa distancia alcanza para que pueda despegar en mínima velocidad.\n");
            }
            else{System.out.println("mal");
            enunciado.setForeground(Color.red);
            enunciado.append("- Distancia máxima incorrecta - Esa distancia no alcanza para despegar a velocidad mínima.\n");
            }
        }

    }});


botondist2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {

        Object obj= e.getSource();
        if(obj.equals(botondist2))
        { 
            if(Integer.parseInt(textfielddist2.getText())>=2000)
            {
            System.out.println("bien");
            enunciado.setForeground(Color.green);
            enunciado.append("\n- Distancia mínima correcta -\n");
            }
            else{System.out.println("mal");
            enunciado.setForeground(Color.red);
            enunciado.append("- Distancia máxima incorrecta -\n");
            }
        }

    }});
    
asked by berlot83 29.10.2016 в 12:43
source

0 answers