Search in sources :

Example 41 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project zaproxy by zaproxy.

the class ScanProgressDialog method getMainPanel.

/**
 * Get the main content panel of the dialog
 *
 * @return the main panel
 */
private JTable getMainPanel() {
    if (table == null) {
        model = new ScanProgressTableModel();
        table = new JTable();
        table.setModel(model);
        table.setRowSelectionAllowed(false);
        table.setColumnSelectionAllowed(false);
        table.setDoubleBuffered(true);
        // First column is for plugin's name
        table.getColumnModel().getColumn(0).setPreferredWidth(256);
        table.getColumnModel().getColumn(1).setPreferredWidth(80);
        // Second column is for plugin's status
        table.getColumnModel().getColumn(2).setPreferredWidth(80);
        table.getColumnModel().getColumn(2).setCellRenderer(new ScanProgressBarRenderer());
        // Third column is for plugin's elapsed time
        DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
        centerRenderer.setHorizontalAlignment(JLabel.CENTER);
        table.getColumnModel().getColumn(3).setPreferredWidth(85);
        table.getColumnModel().getColumn(3).setCellRenderer(centerRenderer);
        // Forth column is for plugin's request count
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
        table.getColumnModel().getColumn(4).setPreferredWidth(60);
        table.getColumnModel().getColumn(4).setCellRenderer(rightRenderer);
        table.getColumnModel().getColumn(5).setPreferredWidth(60);
        table.getColumnModel().getColumn(5).setCellRenderer(rightRenderer);
        // Fifth column is for plugin's completion and actions
        table.getColumnModel().getColumn(6).setPreferredWidth(40);
        table.getColumnModel().getColumn(6).setCellRenderer(new ScanProgressActionRenderer());
        ScanProgressActionListener listener = new ScanProgressActionListener(table, model);
        table.addMouseListener(listener);
        table.addMouseMotionListener(listener);
    }
    return table;
}
Also used : JTable(javax.swing.JTable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 42 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project jmeter by apache.

the class HeaderAsPropertyRendererWrapper method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (delegate instanceof DefaultTableCellRenderer) {
        DefaultTableCellRenderer tr = (DefaultTableCellRenderer) delegate;
        if (table != null) {
            JTableHeader header = table.getTableHeader();
            if (header != null) {
                tr.setForeground(header.getForeground());
                tr.setBackground(header.getBackground());
                tr.setFont(header.getFont());
            }
        }
        tr.setBorder(UIManager.getBorder("TableHeader.cellBorder"));
        tr.setHorizontalAlignment(SwingConstants.CENTER);
    }
    return delegate.getTableCellRendererComponent(table, HeaderAsPropertyRenderer.getText(value, row, column, null), isSelected, hasFocus, row, column);
}
Also used : JTableHeader(javax.swing.table.JTableHeader) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 43 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project druid by alibaba.

the class GroupableTableHeaderUI method paintCell.

private void paintCell(Graphics g, Rectangle cellRect, int columnIndex) {
    TableColumn aColumn = header.getColumnModel().getColumn(columnIndex);
    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;
            }
        };
    }
    String headerValue = aColumn.getHeaderValue().toString();
    Component component = renderer.getTableCellRendererComponent(header.getTable(), headerValue, false, false, -1, columnIndex);
    rendererPane.add(component);
    rendererPane.paintComponent(g, component, header, cellRect.x, cellRect.y, cellRect.width, cellRect.height, true);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTable(javax.swing.JTable) JTableHeader(javax.swing.table.JTableHeader) JComponent(javax.swing.JComponent) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 44 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project druid by alibaba.

the class GroupableTableHeaderUI method paintCell.

private void paintCell(Graphics g, Rectangle cellRect, ColumnGroup cGroup) {
    TableCellRenderer renderer = cGroup.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;
            }
        };
    }
    String headerValue = cGroup.getHeaderValue().toString();
    Component component = renderer.getTableCellRendererComponent(header.getTable(), headerValue, false, false, -1, -1);
    rendererPane.add(component);
    rendererPane.paintComponent(g, component, header, cellRect.x, cellRect.y, cellRect.width, cellRect.height, true);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTable(javax.swing.JTable) JTableHeader(javax.swing.table.JTableHeader) JComponent(javax.swing.JComponent) Component(java.awt.Component) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 45 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project mafscaling by vimsh.

the class ClosedLoop method createAfrDataTable.

private JTable createAfrDataTable(JPanel panel, String tableName, int gridy) {
    final JTable afrTable = new JTable() {

        private static final long serialVersionUID = 6526901361175099297L;

        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    DefaultTableColumnModel afrModel = new DefaultTableColumnModel();
    final TableColumn afrColumn = new TableColumn(0, 250);
    afrColumn.setHeaderValue(tableName);
    afrModel.addColumn(afrColumn);
    JTableHeader lblAfrTableName = afrTable.getTableHeader();
    lblAfrTableName.setColumnModel(afrModel);
    lblAfrTableName.setReorderingAllowed(false);
    DefaultTableCellRenderer headerRenderer = (DefaultTableCellRenderer) lblAfrTableName.getDefaultRenderer();
    headerRenderer.setHorizontalAlignment(SwingConstants.LEFT);
    GridBagConstraints gbc_lblAfrTableName = new GridBagConstraints();
    gbc_lblAfrTableName.insets = new Insets((gridy == 0 ? 0 : 5), 0, 0, 0);
    gbc_lblAfrTableName.anchor = GridBagConstraints.PAGE_START;
    gbc_lblAfrTableName.fill = GridBagConstraints.HORIZONTAL;
    gbc_lblAfrTableName.gridx = 0;
    gbc_lblAfrTableName.gridy = gridy;
    panel.add(lblAfrTableName, gbc_lblAfrTableName);
    afrTable.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            afrColumn.setWidth(afrTable.getWidth());
        }
    });
    Utils.addTableHeaderHighlight(afrTable);
    afrTable.getTableHeader().setReorderingAllowed(false);
    afrTable.setColumnSelectionAllowed(true);
    afrTable.setCellSelectionEnabled(true);
    afrTable.setBorder(new LineBorder(new Color(0, 0, 0)));
    afrTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    afrTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    afrTable.setModel(new DefaultTableModel(AfrTableRowCount, AfrTableColumnCount));
    Utils.initializeTable(afrTable, ColumnWidth);
    if (tableName.equals(Afr1TableName)) {
        Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") } };
        NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class);
        renderer.setFormats(formatMatrix);
    } else if (tableName.equals(Afr2TableName)) {
        Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") }, { new DecimalFormat("#"), new DecimalFormat("#") } };
        NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class);
        renderer.setFormats(formatMatrix);
    }
    GridBagConstraints gbc_afrTable = new GridBagConstraints();
    gbc_afrTable.insets = new Insets(0, 0, 0, 0);
    gbc_afrTable.anchor = GridBagConstraints.PAGE_START;
    gbc_afrTable.gridx = 0;
    gbc_afrTable.gridy = gridy + 1;
    panel.add(afrTable, gbc_afrTable);
    excelAdapter.addTable(afrTable, true, false);
    return afrTable;
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) LineBorder(javax.swing.border.LineBorder) Color(java.awt.Color) DefaultTableModel(javax.swing.table.DefaultTableModel) DecimalFormat(java.text.DecimalFormat) JTableHeader(javax.swing.table.JTableHeader) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Format(java.text.Format) DecimalFormat(java.text.DecimalFormat) JTable(javax.swing.JTable) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)89 JTable (javax.swing.JTable)31 TableColumn (javax.swing.table.TableColumn)28 Component (java.awt.Component)21 JScrollPane (javax.swing.JScrollPane)20 DefaultTableModel (javax.swing.table.DefaultTableModel)18 TableCellRenderer (javax.swing.table.TableCellRenderer)17 MouseEvent (java.awt.event.MouseEvent)14 JLabel (javax.swing.JLabel)14 JComponent (javax.swing.JComponent)12 JTableHeader (javax.swing.table.JTableHeader)12 Dimension (java.awt.Dimension)11 Font (java.awt.Font)11 Color (java.awt.Color)10 GridBagConstraints (java.awt.GridBagConstraints)10 Insets (java.awt.Insets)10 BorderLayout (java.awt.BorderLayout)9 JPanel (javax.swing.JPanel)9 MouseAdapter (java.awt.event.MouseAdapter)8 GridBagLayout (java.awt.GridBagLayout)7