在jtable中添加指定的变量值

时间:2016-04-06 08:32:38

标签: jtable

Object[] column = {"TEST CASES", "RESULTS"};
Object[][] data = {{"Case 1", ""}, {"Case 2", ""}, {"Case 3", ""}, {"Case 4", ""}, {"Case 5", ""}, {"Case 6", ""}, {"Case 7", ""}, {"Case 8", ""}, {"Case 9", ""}, {"Case 10", ""}, {"Case 11", ""}, {"Case 12", ""}, {"Case 13", ""}};

JTable toDoTable = new JTable(data, column) {
    @Override
    public Component prepareRenderer(TableCellRenderer renderer, int rowIndex,
            int columnIndex) {
        if(columnIndex == 1) {
            setFont(new Font("Arial", Font.ITALIC, 12));
        } else {
            setFont(new Font("Arial", Font.BOLD, 12));
        }

        return super.prepareRenderer(renderer, rowIndex, columnIndex);
    }
};
JScrollPane jpane = new JScrollPane(toDoTable);
JPanel panel = new JPanel();
JFrame frame = new JFrame();
frame.setSize(new Dimension(1000, 1000));
frame.setTitle("JTable Font Setting Example");
panel.add(jpane);
frame.add(new JScrollPane(panel));
frame.setVisible(true);  

0 个答案:

没有答案