Search in sources :

Example 41 with TableColumn

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]);
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) TableColumn(javax.swing.table.TableColumn)

Example 42 with TableColumn

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";
}
Also used : TableColumn(javax.swing.table.TableColumn) TableView(com.intellij.ui.table.TableView) Nullable(org.jetbrains.annotations.Nullable)

Example 43 with TableColumn

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);
    }
}
Also used : TableColumn(javax.swing.table.TableColumn)

Example 44 with TableColumn

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());
}
Also used : TableColumn(javax.swing.table.TableColumn) IMiniTable(org.compiere.minigrid.IMiniTable) MiniTable(org.compiere.minigrid.MiniTable)

Example 45 with TableColumn

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");
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn) TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Aggregations

TableColumn (javax.swing.table.TableColumn)272 TableColumnModel (javax.swing.table.TableColumnModel)75 JTable (javax.swing.JTable)51 TableCellRenderer (javax.swing.table.TableCellRenderer)50 JScrollPane (javax.swing.JScrollPane)44 JPanel (javax.swing.JPanel)33 Component (java.awt.Component)31 JLabel (javax.swing.JLabel)26 BoxLayout (javax.swing.BoxLayout)25 JComboBox (javax.swing.JComboBox)23 ActionEvent (java.awt.event.ActionEvent)21 Dimension (java.awt.Dimension)20 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)20 DefaultCellEditor (javax.swing.DefaultCellEditor)19 ActionListener (java.awt.event.ActionListener)17 JButton (javax.swing.JButton)17 FlowLayout (java.awt.FlowLayout)16 DefaultTableModel (javax.swing.table.DefaultTableModel)15 ArrayList (java.util.ArrayList)14 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)12