Search in sources :

Example 66 with JTableHeader

use of javax.swing.table.JTableHeader in project jAudioGIT by dmcennis.

the class FeatureSelectorPanel method setUpFeatureTable.

/**
 * Initialize the table displaying the features which can be extracted.
 */
private void setUpFeatureTable() {
    controller.fstm_.fillTable(controller.dm_.featureDefinitions, controller.dm_.defaults, controller.dm_.is_primary);
    decorator = new SortingTableModelDecorator(controller.fstm_);
    features_table = new JTable(decorator);
    multipleToggleAction = new MultipleToggleAction(features_table);
    String key = "MultipleToggleAction";
    features_table.getInputMap().put(KeyStroke.getKeyStroke(' '), key);
    features_table.getActionMap().put(key, multipleToggleAction);
    int[] width = new int[3];
    width[0] = decorator.getRealPrefferedWidth(features_table, 0);
    width[1] = decorator.getRealPrefferedWidth(features_table, 1);
    width[1] -= 100;
    width[2] = decorator.getRealPrefferedWidth(features_table, 2);
    for (int i = 0; i < width.length; ++i) {
        features_table.getColumnModel().getColumn(i).setPreferredWidth(width[i]);
    }
    // add handler for sorting panel
    JTableHeader header = (JTableHeader) features_table.getTableHeader();
    header.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 1) {
                TableColumnModel tcm = features_table.getColumnModel();
                int column = features_table.convertColumnIndexToModel(tcm.getColumnIndexAtX(e.getX()));
                decorator.sort(column);
            } else {
                decorator.resetIndeci();
            }
        }
    });
    // Set up and display the table
    features_scroll_pane = new JScrollPane(features_table);
    features_panel = new JPanel(new GridLayout(1, 1));
    features_panel.add(features_scroll_pane);
    add(features_panel, BorderLayout.CENTER);
    controller.fstm_.fireTableDataChanged();
    TableColumn tableColumn = features_table.getColumn(features_table.getColumnName(1));
    tableColumn.setCellRenderer(new FeatureDisplay());
    features_table.removeColumn(features_table.getColumn(features_table.getColumnName(3)));
    repaint();
    outer_frame.repaint();
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JTableHeader(javax.swing.table.JTableHeader) TableColumnModel(javax.swing.table.TableColumnModel) FeatureDisplay(jAudioFeatureExtractor.GeneralTools.FeatureDisplay) MultipleToggleAction(jAudioFeatureExtractor.actions.MultipleToggleAction) TableColumn(javax.swing.table.TableColumn)

Example 67 with JTableHeader

use of javax.swing.table.JTableHeader in project knetbuilder by Rothamsted.

the class InteractiveGenomicFilter method calcColumnWidths.

/**
 * calculates the optimal width of a given table by summing the maximal
 * width of each column
 *
 * @param table
 *            table which should be calculated
 */
private void calcColumnWidths(JTable table) {
    // get table header and renderer
    JTableHeader header = table.getTableHeader();
    TableCellRenderer defaultHeaderRenderer = null;
    if (header != null)
        defaultHeaderRenderer = header.getDefaultRenderer();
    TableColumnModel columns = table.getColumnModel();
    TableModel data = table.getModel();
    int margin = columns.getColumnMargin();
    int rowCount = data.getRowCount();
    int totalWidth = 0;
    // go through all columns
    for (int i = columns.getColumnCount() - 1; i >= 0; --i) {
        // get current column
        TableColumn column = columns.getColumn(i);
        int columnIndex = column.getModelIndex();
        int width = -1;
        // get header for current column
        TableCellRenderer h = column.getHeaderRenderer();
        if (h == null)
            h = defaultHeaderRenderer;
        if (h != null) {
            // Not explicitly impossible
            Component c = h.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, -1, i);
            // get header width
            width = (int) (c.getPreferredSize().width * 1.1);
        }
        // go through all rows
        for (int row = rowCount - 1; row >= 0; --row) {
            TableCellRenderer r = table.getCellRenderer(row, i);
            Component c = r.getTableCellRendererComponent(table, data.getValueAt(row, columnIndex), false, false, row, i);
            // max of header width and actual component width
            width = Math.max(width, c.getPreferredSize().width);
        }
        if (width >= 0)
            column.setPreferredWidth(width + margin);
        // setting and summing preferred width of each column
        totalWidth += column.getPreferredWidth();
    }
    // set width to table
    Dimension size = table.getPreferredScrollableViewportSize();
    size.width = totalWidth;
    table.setPreferredScrollableViewportSize(size);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JTableHeader(javax.swing.table.JTableHeader) TableColumnModel(javax.swing.table.TableColumnModel) Dimension(java.awt.Dimension) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn) TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel)

Example 68 with JTableHeader

use of javax.swing.table.JTableHeader in project counselor by clashoflegends.

the class ColumnWidthsAdjuster method calcColumnWidths.

public void calcColumnWidths(JTable table) {
    JTableHeader header = table.getTableHeader();
    TableCellRenderer defaultHeaderRenderer = null;
    if (header != null) {
        defaultHeaderRenderer = header.getDefaultRenderer();
    }
    TableColumnModel columns = table.getColumnModel();
    TableModel data = table.getModel();
    // only JDK1.3
    int margin = columns.getColumnMargin();
    int rowCount = data.getRowCount();
    int totalWidth = 0;
    for (int i = columns.getColumnCount() - 1; i >= 0; --i) {
        TableColumn column = columns.getColumn(i);
        int columnIndex = column.getModelIndex();
        int width = -1;
        TableCellRenderer h = column.getHeaderRenderer();
        if (h == null) {
            h = defaultHeaderRenderer;
        }
        if (h != null) {
            // Not explicitly impossible
            Component c = h.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, -1, i);
            width = c.getPreferredSize().width;
        }
        for (int row = rowCount - 1; row >= 0; --row) {
            TableCellRenderer r = table.getCellRenderer(row, i);
            if (r instanceof ActorActionTableCellRenderer && SettingsManager.getInstance().isConfig("TableActionColumnAdjust", "0", "0")) {
                // don't readjust
                break;
            }
            Component c = r.getTableCellRendererComponent(table, data.getValueAt(row, columnIndex), false, false, row, i);
            width = Math.max(width, c.getPreferredSize().width);
        }
        if (width >= 0) {
            // <1.3: without margin
            column.setPreferredWidth(width + margin + 2);
        } else
            // ???
            ;
        totalWidth += column.getPreferredWidth();
    }
    if (SettingsManager.getInstance().isConfig("TableRowAdjust", "1", "1")) {
        updateRowHeights(table);
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JTableHeader(javax.swing.table.JTableHeader) TableColumnModel(javax.swing.table.TableColumnModel) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn) TableModel(javax.swing.table.TableModel)

Example 69 with JTableHeader

use of javax.swing.table.JTableHeader in project RomRaider by RomRaider.

the class NCSLearningTableValuesResultsPanel method formatTableHeader.

private final JTableHeader formatTableHeader(JTable table) {
    final JTableHeader th = table.getTableHeader();
    th.setReorderingAllowed(false);
    th.setDefaultRenderer(new CentreRenderer(table));
    SetFont.bold(th, 11);
    return th;
}
Also used : JTableHeader(javax.swing.table.JTableHeader) CentreRenderer(com.romraider.logger.ecu.ui.swing.tools.tablemodels.renderers.CentreRenderer)

Example 70 with JTableHeader

use of javax.swing.table.JTableHeader in project knime-base by knime.

the class AbstractCorrelationComputeNodeView method changeRenderer.

/**
 * @param renderer the table's new renderer
 */
protected void changeRenderer(final String renderer) {
    TableContentView tcv = m_tableView.getContentTable();
    tcv.changeRenderer(DoubleCell.TYPE, renderer);
    Component c = m_tableView.getCorner(ScrollPaneConstants.UPPER_LEFT_CORNER);
    LegendCornerAll cornerRenderer = null;
    if (c instanceof JTableHeader) {
        JTableHeader corner = (JTableHeader) c;
        TableCellRenderer ren = corner.getDefaultRenderer();
        if (ren instanceof LegendCornerAll) {
            cornerRenderer = (LegendCornerAll) ren;
        }
    }
    if (cornerRenderer != null) {
        if (renderer.equals(ColorRender.DESCRIPTION)) {
            cornerRenderer.setPaintLegend(true);
            // no need to set column header height, done by label UI
            tcv.setColumnWidth(15);
            TableCellRenderer r = m_tableView.getContentTable().getTableHeader().getDefaultRenderer();
            if (r instanceof JLabel) {
                ((JLabel) r).setUI(new VerticalLabelUI());
            }
            m_tableView.setColumnHeaderViewHeight(-1);
        } else {
            cornerRenderer.setPaintLegend(false);
            m_tableView.setColumnHeaderViewHeight(16);
            tcv.setColumnWidth(75);
            TableCellRenderer r = m_tableView.getContentTable().getTableHeader().getDefaultRenderer();
            if (r instanceof JLabel) {
                ((JLabel) r).updateUI();
            }
        }
    }
    m_currentRendererID = renderer;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTableHeader(javax.swing.table.JTableHeader) JLabel(javax.swing.JLabel) TableContentView(org.knime.core.node.tableview.TableContentView) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Aggregations

JTableHeader (javax.swing.table.JTableHeader)240 TableColumn (javax.swing.table.TableColumn)59 MouseEvent (java.awt.event.MouseEvent)56 JTable (javax.swing.JTable)53 TableColumnModel (javax.swing.table.TableColumnModel)45 TableCellRenderer (javax.swing.table.TableCellRenderer)38 Component (java.awt.Component)35 MouseAdapter (java.awt.event.MouseAdapter)32 DefaultTableModel (javax.swing.table.DefaultTableModel)29 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)28 Color (java.awt.Color)25 JPanel (javax.swing.JPanel)25 JScrollPane (javax.swing.JScrollPane)25 JLabel (javax.swing.JLabel)23 Point (java.awt.Point)22 Dimension (java.awt.Dimension)20 BorderLayout (java.awt.BorderLayout)18 JComponent (javax.swing.JComponent)17 TableModel (javax.swing.table.TableModel)17 JButton (javax.swing.JButton)14