Example usage for weka.gui JTableHelper setOptimalHeaderWidth

List of usage examples for weka.gui JTableHelper setOptimalHeaderWidth

Introduction

In this page you can find the example usage for weka.gui JTableHelper setOptimalHeaderWidth.

Prototype

public static void setOptimalHeaderWidth(JTable jtable, int col) 

Source Link

Document

sets the optimal header width for the given column

Usage

From source file:meka.gui.dataviewer.DataTable.java

License:Open Source License

/**
 * sets the cell renderer and calcs the optimal column width
 *///w ww  .j a  v a 2  s .co  m
private void setLayout() {
    DataSortedTableModel arffModel;
    int i;
    JComboBox combo;
    Enumeration<Object> enm;

    arffModel = (DataSortedTableModel) getModel();

    for (i = 0; i < getColumnCount(); i++) {
        // optimal colwidths (only according to header!)
        JTableHelper.setOptimalHeaderWidth(this, i);

        // CellRenderer
        getColumnModel().getColumn(i).setCellRenderer(new DataTableCellRenderer());

        // CellEditor
        if (i > 0) {
            if (arffModel.getType(i) == Attribute.NOMINAL) {
                combo = new JComboBox();
                combo.addItem(null);
                enm = arffModel.getInstances().attribute(i - 1).enumerateValues();
                while (enm.hasMoreElements()) {
                    Object o = enm.nextElement();
                    if (o instanceof SerializedObject) {
                        ((SerializedObject) o).getObject();
                    }
                    combo.addItem(o);
                }
                getColumnModel().getColumn(i).setCellEditor(new DefaultCellEditor(combo));
            } else {
                getColumnModel().getColumn(i).setCellEditor(null);
            }
        }
    }
}