use of javax.swing.table.TableColumnModel in project processdash by dtuma.
the class TeamMemberListTable method recreateWeekColumnsToFit.
/**
* Recreate the columns in the table model, to display data for as many
* weeks as possible (within the constraints of the width of the table)
*/
private void recreateWeekColumnsToFit() {
TeamMemberList teamList = getTeamMemberList();
TableColumnModel tcm = getColumnModel();
// compute the amount of space allocated to the weekly columns.
// first, get the width of the entire table
int tableWidth = getWidth();
int width = tableWidth;
// next, subtract out the width of the initial, fixed columns.
for (int i = COL_WIDTHS.length; i-- > 0; ) width = width - COL_WIDTHS[i];
// then, subtract out the width of the grippy column.
width = width - GRIPPY_WIDTH - getIntercellSpacing().width;
int numWeekColumns = Math.max(0, width / WEEK_COL_WIDTH);
int extraWidth = width - (numWeekColumns * WEEK_COL_WIDTH);
TableColumn firstCol = tcm.getColumn(0);
firstCol.setWidth(COL_WIDTHS[0] + extraWidth);
int existingNumWeekColumns = teamList.getNumWeekColumns();
if (existingNumWeekColumns != numWeekColumns) {
// remove the grippy column.
removeLastColumn(tcm);
// remove any weekly columns that are no longer needed
for (int i = numWeekColumns; i < existingNumWeekColumns; i++) removeLastColumn(tcm);
// reconfigure the table for the desired number of weekly columns
teamList.setNumWeekColumns(numWeekColumns);
// add any weekly columns that are now needed
int colIdx = tcm.getColumnCount();
for (int i = existingNumWeekColumns; i < numWeekColumns; i++) tcm.addColumn(createWeekColumn(colIdx++));
// add a grippy column at the end.
tcm.addColumn(createGrippyColumn(colIdx));
}
repositionHeaderDecorations(tableWidth, numWeekColumns);
}
use of javax.swing.table.TableColumnModel in project groovy-core by groovy.
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 smile by haifengl.
the class TableColumnSettings method saveSettings.
private void saveSettings() {
TableColumnModel columnModel = table.getColumnModel();
prefs.putInt(id + "-visible-column-count", columnModel.getColumnCount());
for (int i = 0; i < columnModel.getColumnCount(); i++) {
TableColumn col = columnModel.getColumn(i);
int idx = col.getModelIndex();
int width = col.getWidth();
prefs.putInt(id + "-column-width-" + idx, width);
prefs.putInt(id + "-column-order-" + i, idx);
}
}
use of javax.swing.table.TableColumnModel in project antlrworks by antlr.
the class XJTableView method autoresizeColumns.
public void autoresizeColumns() {
resizeTableColumnsToFitContent(table, 20);
TableColumnModel model = table.getColumnModel();
int columnTotalWidth = 0;
for (int i = 0; i < model.getColumnCount() - 1; i++) {
columnTotalWidth += model.getColumn(i).getPreferredWidth();
}
// Note: this offset should be UI dependent
int offset;
if (getVerticalScrollBar().isVisible()) {
if (XJSystem.isWindows()) {
offset = 20;
} else {
offset = 20;
}
} else {
if (XJSystem.isWindows()) {
offset = 3;
} else {
offset = 4;
}
}
int spWidth = getWidth();
if (spWidth == 0) {
spWidth = getPreferredSize().width;
}
if (model.getColumnCount() > 0) {
TableColumn c = model.getColumn(model.getColumnCount() - 1);
int prefWidth = c.getPreferredWidth();
c.setPreferredWidth(Math.max(spWidth - columnTotalWidth - offset, prefWidth));
}
}
use of javax.swing.table.TableColumnModel in project druid by alibaba.
the class GroupableTableHeaderUI method getHeaderHeight.
public int getHeaderHeight() {
int height = 0;
TableColumnModel columnModel = header.getColumnModel();
for (int column = 0; column < columnModel.getColumnCount(); column++) {
TableColumn aColumn = columnModel.getColumn(column);
TableCellRenderer renderer = aColumn.getHeaderRenderer();
if (renderer == null) {
renderer = new DefaultTableCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JTableHeader header = table.getTableHeader();
if (header != null) {
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(header.getFont());
}
setHorizontalAlignment(JLabel.CENTER);
setText((value == null) ? "" : value.toString());
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
return this;
}
};
}
Component comp = renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false, -1, column);
int cHeight = comp.getPreferredSize().height;
Enumeration<ColumnGroup> enumeration = ((GroupableTableHeader) header).getColumnGroups(aColumn);
if (enumeration != null) {
while (enumeration.hasMoreElements()) {
ColumnGroup cGroup = (ColumnGroup) enumeration.nextElement();
cHeight += cGroup.getSize(header.getTable()).height;
}
}
height = Math.max(height, cHeight);
}
height = Math.max(height, m_height);
return height;
}
Aggregations