通过Jsoup将提取的元素显示到JTable

时间:2013-06-08 06:09:44

标签: java swing jtable jsoup

我正在使用JSoup来提取标签中的元素。这是我使用.text()时的结果:

ACCOUNT
0000001
0000002
0000003

NAME
Customer1
Customer2
Customer3

BALANCE
100.00
200.00
550.00

我想将它显示在我使用JTable创建的表中。我需要有人指导我用一些示例代码来解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class SimpleTable {
    public SimpleTable(){                                                                  
        JFrame f = new JFrame();
        Object[][] tableInputs = {
        { 
            "Customer1","0000001", "100.00",
        },
        { 
            "Customer2", "0000002", "200.00"
        },
        { 
            "Customer3", "0000003", "550.00"
        }};
        String[] header = { "NAME", "ACCOUNT", "BALANCE" };
        JTable table = new JTable(tableInputs, header);
        table.setPreferredScrollableViewportSize(new Dimension(500, 100));
        JScrollPane scrollPane = new JScrollPane(table);
        f.add(scrollPane);
        f.setTitle("Simple Table");
        f.pack();
        f.setVisible(true);
    }
    public static void main(String[] args) {
        SimpleTable b = new SimpleTable();
    }
}