标签:eval const over cto tde ati for jtable final
public class ExampleFrame_03 extends JFrame { public static void main(String[] args) { // TODO Auto-generated method stub ExampleFrame_03 exampleFrame_02 = new ExampleFrame_03(); exampleFrame_02.setVisible(true); } public ExampleFrame_03() { // TODO Auto-generated constructor stub super(); setTitle("定义表格"); setBounds(100, 100, 500, 375); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JScrollPane scrollPane = new JScrollPane(); getContentPane().add(scrollPane, BorderLayout.CENTER); String[] columnNames = { "A", "B", "C", "D", "E", "F", "G" }; Vector<String> columnNameV = new Vector<>(); for (int i = 0; i < columnNames.length; i++) { columnNameV.add(columnNames[i]); } Vector<Vector<String>> tableValueV = new Vector<>(); for (int i = 0; i < 21; i++) { Vector<String> iV = new Vector<>(); for (int j = 0; j < columnNames.length; j++) { iV.add(columnNames[j] + i); } tableValueV.add(iV); } JTable table = new MTable(tableValueV, columnNameV); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.setSelectionBackground(Color.YELLOW); table.setSelectionForeground(Color.RED); table.setRowHeight(30); scrollPane.setViewportView(table); } private class MTable extends JTable { private static final long serialVersionUID = 1L; public MTable(Vector<Vector<String>> rowData, Vector<String> columnNames) { super(rowData, columnNames); } @Override public JTableHeader getTableHeader() { // TODO Auto-generated method stub JTableHeader tableHeader = super.getTableHeader(); tableHeader.setReorderingAllowed(false); DefaultTableCellRenderer hr = (DefaultTableCellRenderer) tableHeader.getDefaultRenderer(); hr.setHorizontalAlignment(DefaultTableCellRenderer.CENTER); return tableHeader; } public TableCellRenderer getDefaultRenderer(Class<?> columnClass) { DefaultTableCellRenderer cr = (DefaultTableCellRenderer)super.getDefaultRenderer(columnClass); cr.setHorizontalAlignment(DefaultTableCellRenderer.CENTER); return cr; } public boolean isCellEditable(int row ,int column) { return false; } } }
标签:eval const over cto tde ati for jtable final
原文地址:https://www.cnblogs.com/dulute/p/10675487.html