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);
}
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());
}
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());
}
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]);
}
}
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();
}
Aggregations