use of javax.swing.table.TableColumn in project intellij-community by JetBrains.
the class JTableWrapper method packColumns.
private void packColumns() {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) myTable.getColumnModel();
int[] colMinWidths = new int[myColumns.length];
for (int iColumn = 0; iColumn < myColumns.length; iColumn++) {
TableColumn col = colModel.getColumn(iColumn);
colMinWidths[iColumn] = col.getMinWidth();
if (!myColumns[iColumn].needPack()) {
col.setWidth(col.getMinWidth());
continue;
}
// Get width of column header
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = myTable.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(myTable, col.getHeaderValue(), false, false, 0, 0);
int colWidth = comp.getPreferredSize().width;
for (int iRow = 0; iRow < myTable.getRowCount(); iRow++) {
renderer = myTable.getCellRenderer(iRow, iColumn);
comp = renderer.getTableCellRendererComponent(myTable, myTable.getValueAt(iRow, iColumn), false, false, iRow, iColumn);
colWidth = Math.max(colWidth, comp.getPreferredSize().width);
}
colWidth += 2 * COLUMN_HEADER_MARGIN_WIDTH;
col.setMaxWidth(colWidth);
col.setMinWidth(colWidth);
}
for (int iColumn = 0; iColumn < myColumns.length; iColumn++) {
TableColumn col = colModel.getColumn(iColumn);
col.setMinWidth(colMinWidths[iColumn]);
}
}
use of javax.swing.table.TableColumn in project intellij-community by JetBrains.
the class FileHistoryColumnWrapper method getMaxValue.
@Nullable
private String getMaxValue(@NotNull String columnHeader) {
TableView table = getDualView().getFlatView();
if (table.getRowCount() == 0)
return null;
final Enumeration<TableColumn> columns = table.getColumnModel().getColumns();
int idx = 0;
while (columns.hasMoreElements()) {
TableColumn column = columns.nextElement();
if (columnHeader.equals(column.getHeaderValue())) {
break;
}
++idx;
}
if (idx >= table.getColumnModel().getColumnCount() - 1)
return null;
final FontMetrics fm = table.getFontMetrics(table.getFont().deriveFont(Font.BOLD));
final Object header = table.getColumnModel().getColumn(idx).getHeaderValue();
double maxValue = fm.stringWidth((String) header);
String value = (String) header;
for (int i = 0; i < table.getRowCount(); i++) {
final Object at = table.getValueAt(i, idx);
if (at instanceof String) {
final int newWidth = fm.stringWidth((String) at);
if (newWidth > maxValue) {
maxValue = newWidth;
value = (String) at;
}
}
}
return value + "ww";
}
use of javax.swing.table.TableColumn in project intellij-community by JetBrains.
the class TableColumnAnimator method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (myColumns.isEmpty()) {
stop();
if (myDone != null) {
SwingUtilities.invokeLater(myDone);
}
return;
}
final TableColumn c = myColumns.get(0).first;
if (!added) {
myTable.addColumn(c);
c.setMaxWidth(0);
c.setPreferredWidth(0);
c.setWidth(0);
added = true;
}
final int prefWidth = myColumns.get(0).second.intValue();
int width = c.getWidth();
width = Math.min(width + myStep, prefWidth);
c.setMaxWidth(width);
c.setPreferredWidth(width);
c.setWidth(width);
if (width == prefWidth) {
added = false;
myColumns.remove(0);
//c.setMaxWidth(oldMaxWidth);
}
}
use of javax.swing.table.TableColumn in project adempiere by adempiere.
the class VCreateFromShipmentUI method configureMiniTable.
@Override
protected void configureMiniTable(IMiniTable miniTable) {
super.configureMiniTable(miniTable);
// Set custom cell editor to enable editing locators
MiniTable swingTable = (MiniTable) miniTable;
TableColumn col = swingTable.getColumn(3);
col.setCellEditor(new InnerLocatorTableCellEditor());
}
use of javax.swing.table.TableColumn in project adempiere by adempiere.
the class VBrowserTable method autoSize.
/**
* Size Columns.
* Uses Mimimun Column Size
*/
public void autoSize() {
if (!autoResize)
return;
long start = System.currentTimeMillis();
//
// making sure it fits in a column
final int SLACK = 8;
// max size of a column
final int MAXSIZE = 300;
//
TableModel model = this.getModel();
int size = model.getColumnCount();
// for all columns
for (int col = 0; col < size; col++) {
// Column & minimum width
TableColumn tc = this.getColumnModel().getColumn(col);
int width = 0;
if (m_minWidth.size() > col)
width = ((Integer) m_minWidth.get(col)).intValue();
// log.config( "Column=" + col + " " + column.getHeaderValue());
// Header
TableCellRenderer renderer = tc.getHeaderRenderer();
if (renderer == null)
renderer = new DefaultTableCellRenderer();
Component comp = renderer.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, 0);
// log.fine( "Hdr - preferred=" + comp.getPreferredSize().width + ", width=" + comp.getWidth());
width = Math.max(width, comp.getPreferredSize().width + SLACK);
// Cells
// first 30 rows
int maxRow = Math.min(30, getRowCount());
for (int row = 0; row < maxRow; row++) {
renderer = getCellRenderer(row, col);
comp = renderer.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col);
if (comp != null) {
int rowWidth = comp.getPreferredSize().width + SLACK;
width = Math.max(width, rowWidth);
}
}
// Width not greater ..
width = Math.min(MAXSIZE, width);
tc.setPreferredWidth(width);
// log.fine( "width=" + width);
}
// for all columns
log.finer("Cols=" + size + " - " + (System.currentTimeMillis() - start) + "ms");
}
Aggregations