Example usage for javax.swing JTable getAutoResizeMode

List of usage examples for javax.swing JTable getAutoResizeMode

Introduction

In this page you can find the example usage for javax.swing JTable getAutoResizeMode.

Prototype

public int getAutoResizeMode() 

Source Link

Document

Returns the auto resize mode of the table.

Usage

From source file:com.sshtools.common.ui.PreferencesStore.java

/**
 *
 *
 * @param table//from   w  ww  . j  a  v a  2s  .c o  m
 * @param pref
 * @param defaultWidths
 *
 * @throws IllegalArgumentException
 */
public static void restoreTableMetrics(JTable table, String pref, int[] defaultWidths) {
    //  Check the table columns may be resized correctly
    if (table.getAutoResizeMode() != JTable.AUTO_RESIZE_OFF) {
        throw new IllegalArgumentException("Table AutoResizeMode must be JTable.AUTO_RESIZE_OFF");
    }

    //  Restore the table column widths and positions
    for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
        try {
            table.moveColumn(table.convertColumnIndexToView(getInt(pref + ".column." + i + ".position", i)), i);
            table.getColumnModel().getColumn(i)
                    .setPreferredWidth(getInt(pref + ".column." + i + ".width",
                            (defaultWidths == null) ? table.getColumnModel().getColumn(i).getPreferredWidth()
                                    : defaultWidths[i]));
        } catch (NumberFormatException nfe) {
        }
    }
}