Search in sources :

Example 1 with TableColumnModel

use of javax.swing.table.TableColumnModel in project groovy by apache.

the class TableSorter method addMouseListenerToHeaderInTable.

// There is no-where else to put this.
// Add a mouse listener to the Table to trigger a table sort
// when a column heading is clicked in the JTable.
public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            TableColumnModel columnModel = tableView.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX());
            int column = tableView.convertColumnIndexToModel(viewColumn);
            if (e.getClickCount() == 1 && column != -1) {
                if (lastSortedColumn == column)
                    ascending = !ascending;
                sorter.sortByColumn(column, ascending);
                lastSortedColumn = column;
            }
        }
    };
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) TableColumnModel(javax.swing.table.TableColumnModel) JTableHeader(javax.swing.table.JTableHeader)

Example 2 with TableColumnModel

use of javax.swing.table.TableColumnModel in project druid by alibaba.

the class DruidSQLPanel method addTableGroup.

private void addTableGroup() {
    TableColumnModel cm = table.getColumnModel();
    // System.out.println(SHOW_LIST.size());
    for (int i : listHistogram) {
        groupHistogram.add(cm.getColumn(i));
    }
    for (int j : listEffectedRowCountHistogram) {
        groupEffectedRowCountHistogram.add(cm.getColumn(j));
    }
    for (int x : listExecuteAndResultHoldTimeHistogram) {
        groupExecuteAndResultHoldTimeHistogram.add(cm.getColumn(x));
    }
    for (int y : listFetchRowCountHistogram) {
        groupFetchRowCountHistogram.add(cm.getColumn(y));
    }
    GroupableTableHeader header = (GroupableTableHeader) table.getTableHeader();
    header.addColumnGroup(groupHistogram);
    header.addColumnGroup(groupEffectedRowCountHistogram);
    header.addColumnGroup(groupExecuteAndResultHoldTimeHistogram);
    header.addColumnGroup(groupFetchRowCountHistogram);
    header.setUI(new GroupableTableHeaderUI());
}
Also used : TableColumnModel(javax.swing.table.TableColumnModel) GroupableTableHeaderUI(com.alibaba.druid.support.jconsole.model.GroupableTableHeaderUI) GroupableTableHeader(com.alibaba.druid.support.jconsole.model.GroupableTableHeader)

Example 3 with TableColumnModel

use of javax.swing.table.TableColumnModel in project druid by alibaba.

the class GroupableTableHeaderUI method createHeaderSize.

private Dimension createHeaderSize(long width) {
    TableColumnModel columnModel = header.getColumnModel();
    width += columnModel.getColumnMargin() * columnModel.getColumnCount();
    if (width > Integer.MAX_VALUE) {
        width = Integer.MAX_VALUE;
    }
    return new Dimension((int) width, getHeaderHeight());
}
Also used : TableColumnModel(javax.swing.table.TableColumnModel) Dimension(java.awt.Dimension)

Example 4 with TableColumnModel

use of javax.swing.table.TableColumnModel in project smile by haifengl.

the class TableColumnSettings method restoreSettings.

private void restoreSettings() {
    TableColumnModel columnModel = table.getColumnModel();
    // restore column width
    for (int i = 0; i < columnModel.getColumnCount(); i++) {
        TableColumn col = columnModel.getColumn(i);
        int idx = col.getModelIndex();
        int width = prefs.getInt(id + "-column-width-" + idx, 0);
        if (width != 0) {
            col.setPreferredWidth(width);
        }
    }
    // restore column order
    TableColumn[] column = new TableColumn[columnModel.getColumnCount()];
    for (int i = 0; i < column.length; i++) {
        column[i] = columnModel.getColumn(i);
    }
    // remove all columns
    while (columnModel.getColumnCount() > 0) {
        columnModel.removeColumn(columnModel.getColumn(0));
    }
    // add them back with saved order
    int visibleColumnCount = prefs.getInt(id + "-visible-column-count", column.length);
    for (int i = 0; i < visibleColumnCount; i++) {
        int idx = prefs.getInt(id + "-column-order-" + i, i);
        columnModel.addColumn(column[idx]);
    }
}
Also used : TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn)

Example 5 with TableColumnModel

use of javax.swing.table.TableColumnModel in project pcgen by PCGen.

the class Initiative method addColumn.

private void addColumn(String name, int width) {
    DefaultTableModel tabModel = (DefaultTableModel) combatantTable.getModel();
    TableColumnModel colModel = combatantTable.getColumnModel();
    tabModel.addColumn(name);
    TableColumn column = colModel.getColumn(colModel.getColumnCount() - 1);
    column.setPreferredWidth(width);
    column.setWidth(width);
    column.setIdentifier(name);
    columnList = getColumnOrder();
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn)

Aggregations

TableColumnModel (javax.swing.table.TableColumnModel)168 TableColumn (javax.swing.table.TableColumn)66 JTable (javax.swing.JTable)34 JScrollPane (javax.swing.JScrollPane)31 JButton (javax.swing.JButton)30 BoxLayout (javax.swing.BoxLayout)24 TableCellEditor (javax.swing.table.TableCellEditor)23 ButtonEditor (jmri.util.table.ButtonEditor)23 ButtonRenderer (jmri.util.table.ButtonRenderer)23 JLabel (javax.swing.JLabel)22 JPanel (javax.swing.JPanel)22 ActionEvent (java.awt.event.ActionEvent)20 ActionListener (java.awt.event.ActionListener)16 FlowLayout (java.awt.FlowLayout)15 Border (javax.swing.border.Border)13 Iterator (java.util.Iterator)12 Set (java.util.Set)12 JTableHeader (javax.swing.table.JTableHeader)12 TableCellRenderer (javax.swing.table.TableCellRenderer)12 Container (java.awt.Container)10