有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

将java中的HTML与现有变量一起使用

我试图使用LinkedList的内容在JTextArea中创建一个表。现在我有:

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");
    }

但是,在编译时,它仍然是纯文本: 1

有没有关于展示桌子的建议

提前谢谢


共 (1) 个答案

  1. # 1 楼答案

    TextArea用于显示简单文本,而JEditorPane用于显示HTML文本

    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);
    }
    }