0

I am trying to create a table within a JTextArea using the contents of a LinkedList. Right now I have:

for(int i = 0; i < commands.size(); i++) {
        String row = "<html><table><tr><td>"+commands.get(i)+"</td><td>"+desc.get(i)+"</td></tr></table></html>";
        MainConsole.console.textArea.append(row+"\n");
    }

However, when it compiles, it remains as plain text: 1

Any tips on getting the table to display?

Thanks in advance.

2
  • If you use a JEditorPane, you can set the content type to html: docs.oracle.com/javase/7/docs/api/javax/swing/… Commented Oct 25, 2018 at 18:56
  • I think there's a way to do this without explicitly setting the content type, but setting the content type certainly works. Commented Oct 25, 2018 at 19:28

1 Answer 1

2

TextArea is for displaying simple text, use JEditorPane for HTML text

public class TestJEditorPane {
public static void main(String[] args) {
    JFrame frame = new JFrame();

    JEditorPane pane = new JEditorPane();
    pane.setContentType("text/html");
    pane.setText("<html><b>Hello World</b></html>");

    frame.add(pane);
    frame.setSize(200, 200);
    frame.setVisible(true);
}
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.