如何更改以下jtable标题的字体

时间:2016-09-21 09:54:51

标签: java jtable

如何在jtable标题中设置字体粗体。

我的代码......

            table = new JTable();
            model = new DefaultTableModel(){
                        public Class<?> getColumnClass(int column) {
                                     switch (column) {
                                     case 0:
                                       return Boolean.class;
                                     case 1:
                                       return String.class;
                                     case 2:
                                       return String.class;
                                     -----
                                     ----
                                       case 19 :
                                        return String.class;
                                 }
                         }

                 public boolean isCellEditable(int row, int col) {
                         if (col > 0) {
                             return false;
                         } else
                             return (true);
                     }

             };

                               model.addColumn(null);           
                         String[] name = {"one","two","three",
                                       "four","five",
                                       "six","seven","eight","nine","ten","eleven","tweleve","thirteen","fourteen",
                                       "fiveteen","sixteen","seventeen","eightteen","nineteen","twenty"};
                         for(int i=0;i<name.length;i++){  
                                model.addColumn(name[i]);
                         }  

                         DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
                         centerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
                         table.setDefaultRenderer(String.class, centerRenderer);
                         table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                         table.setAutoCreateRowSorter(true);
                         table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                         table.setModel(model);
                         TableColumn tc = table.getColumnModel().getColumn(0);
                         tc.setCellEditor(table.getDefaultEditor(Boolean.class));
                         tc.setCellRenderer(table.getDefaultRenderer(Boolean.class));
                         tc.setHeaderRenderer(new CheckBoxHeader11(new MyItemListener()));
                         tc.setMaxWidth(25); 
                         tableScroll = new JScrollPane(table); 

1 个答案:

答案 0 :(得分:1)

//设置列名称的字体
table.getTableHeader()。setFont(new Font(“Ariel”,Font.BOLD,27));