開発メモ

開発用のメモです。

javax.swing テーブル+スクロール

JTable table = new JTable();
table.setBorder(new EmptyBorder(1, 1, 1, 1));
DefaultTableModel dm = new DefaultTableModel(new String[] {
        LABEL_MNG_NO, 
        LABEL_CREATED, 
        LABEL_TRADER, 
        LABEL_HAULER,
        LABEL_CONSIGNMENT, 
        LABEL_OCCURENCE, 
        LABEL_OCCURENCE_AREA,
        LABEL_SITE, 
        LABEL_CLAIM, 
        LABEL_QTY }, 20) {
    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }
};
table.setModel(dm);
Enumeration<TableColumn> columns;
columns = table.getColumnModel().getColumns();

while (columns.hasMoreElements()) {
TableColumn column = (TableColumn) columns.nextElement();
    column.setPreferredWidth(96);
}

table.getTableHeader().setReorderingAllowed(false);
JScrollPane tablePane = new JScrollPane(table);
tablePane.setBorder(new EmptyBorder(1, 1, 1, 1));
Twitter: @asahina_alice