Example usage for javax.swing.table TableColumn sizeWidthToFit

List of usage examples for javax.swing.table TableColumn sizeWidthToFit

Introduction

In this page you can find the example usage for javax.swing.table TableColumn sizeWidthToFit.

Prototype

public void sizeWidthToFit() 

Source Link

Document

Resizes the TableColumn to fit the width of its header cell.

Usage

From source file:ThreadViewer.java

public ThreadViewer() {

    JTable table = new JTable(tableModel);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);

    TableColumnModel colModel = table.getColumnModel();
    int numColumns = colModel.getColumnCount();

    for (int i = 0; i < numColumns - 1; i++) {
        TableColumn col = colModel.getColumn(i);

        col.sizeWidthToFit();
        col.setPreferredWidth(col.getWidth() + 5);
        col.setMaxWidth(col.getWidth() + 5);
    }// w w w .  j  a  v  a 2  s .  co  m

    JScrollPane sp = new JScrollPane(table);

    setLayout(new BorderLayout());
    add(sp, BorderLayout.CENTER);
}