I can recognize file extensions but still cant give different color for different extensions when I am printing to TextArea , is it because TextArea and all the font changes after running the program to *"serif", Font.ROMAN_BASELINE, 5*

  public void setScanResult(ArrayList<String> x) {


    for (int i = 0; i < x.size(); i++) {

        if (x.get(i).endsWith(".txt")) {

            Font fono1 = new Font("sansserif", Font.BOLD, 50);
            textArea.setFont(fono1);
            textArea.append((String) x.get(i));
        } else if (x.get(i).endsWith(".xls")) {

            Font fono2 = new Font("Monospaced", Font.ITALIC, 10);
            textArea.setFont(fono2);
            textArea.append((String) x.get(i));
        } else {

            Font fono3 = new Font("serif", Font.ROMAN_BASELINE, 5);
            textArea.setFont(fono3);
            textArea.append((String) x.get(i));
        }
        textArea.append("\n");
        //textArea.append((String) x.get(i));

    }

    x.clear();
有帮助吗?

解决方案

JTextArea is for plain text, not formatted. That means that at any moment, it can have one font, at one size, in one color.

If the app. needs formatted text, look to JEditorPane or JTextPane. See How to Use Editor Panes and Text Panes for details and working source.

enter image description here

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top