Search in sources :

Example 31 with TableColumn

use of javax.swing.table.TableColumn in project ACS by ACS-Community.

the class AlarmDetailTable method setTitleColumnSize.

/**
	 * Calculate the width of the first column to be at least wide 
	 * enough to contain the titles in {@link RowTitles}.
	 * <P>
	 * The width of the column is the greatest between the width needed
	 * to show the title or the passed width
	 * 
	 * @param sz A vector of string (can be <code>null</code>)
	 * @return The width of the first column
	 */
private int setTitleColumnSize(Vector<String> strings) {
    BufferedImage bImg = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2D = bImg.createGraphics();
    FontMetrics fm = g2D.getFontMetrics();
    int sz = 0;
    for (RowTitles row : RowTitles.values()) {
        if (sz < fm.stringWidth(row.title)) {
            sz = fm.stringWidth(row.title);
        }
    }
    if (strings != null) {
        for (String str : strings) {
            if (sz < fm.stringWidth(str)) {
                sz = fm.stringWidth(str);
            }
        }
    }
    sz += 20;
    TableColumn col = getColumnModel().getColumn(0);
    col.setPreferredWidth(sz);
    col.setMinWidth(sz);
    col.setMaxWidth(sz);
    col.setWidth(sz);
    col.setResizable(false);
    col = getColumnModel().getColumn(1);
    col.setResizable(true);
    return sz;
}
Also used : FontMetrics(java.awt.FontMetrics) TableColumn(javax.swing.table.TableColumn) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 32 with TableColumn

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

the class TableColumnManager method columnMoved.

@Override
public void columnMoved(TableColumnModelEvent e) {
    if (e.getFromIndex() == e.getToIndex()) {
        return;
    }
    // A table column has been moved one position to the left or right
    // in the view of the table so we need to update the manager to
    // track the new location
    int index = e.getToIndex();
    TableColumn column = columnModel.getColumn(index);
    allColumns.remove(column);
    if (index == 0) {
        allColumns.add(0, column);
    } else {
        index--;
        TableColumn visibleColumn = columnModel.getColumn(index);
        int insertionColumn = allColumns.indexOf(visibleColumn);
        allColumns.add(insertionColumn + 1, column);
    }
}
Also used : TableColumn(javax.swing.table.TableColumn)

Example 33 with TableColumn

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

the class HttpPanelParamTableView method setEditable.

@Override
public void setEditable(boolean editable) {
    if (isEditable != editable) {
        if (isEditable) {
            table.getColumnModel().removeColumn(table.getColumnModel().getColumn(3));
        } else {
            TableColumn column = new TableColumn(3, 150, new ComboBoxCellRenderer(comboBoxAddIns), new DefaultCellEditor(comboBoxAddIns));
            column.setPreferredWidth(150);
            column.setMaxWidth(150);
            table.addColumn(column);
        }
        isEditable = editable;
        httpPanelTabularModel.setEditable(editable);
    }
}
Also used : TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 34 with TableColumn

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

the class DruidSqlDetailFrame method addTable.

/**
     * 将表格添加到contentPanel对象内部。
     * 
     * @param contentPanel JPanel对象
     * @param 当前表格的标题
     * @param data 当前表格的数据
     */
private void addTable(JPanel contentPanel, String title, ArrayList<LinkedHashMap<String, Object>> data) {
    final JPanel content1 = new JPanel();
    content1.setLayout(new BorderLayout());
    content1.setBorder((TitledBorder) BorderFactory.createTitledBorder(title));
    contentPanel.add(content1);
    ColumnData colData = TableDataProcessor.row2col(data);
    JTable table = new JTable();
    DruidTableModel tableModel = new DruidTableModel(colData.getData());
    table.setModel(tableModel);
    TableColumn col = table.getColumnModel().getColumn(0);
    col.setCellRenderer(new DruidTableCellRenderer());
    final JTableHeader header1 = table.getTableHeader();
    content1.add(header1, BorderLayout.NORTH);
    content1.add(table);
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable) JTableHeader(javax.swing.table.JTableHeader) ColumnData(com.alibaba.druid.support.jconsole.util.TableDataProcessor.ColumnData) DruidTableModel(com.alibaba.druid.support.jconsole.model.DruidTableModel) DruidTableCellRenderer(com.alibaba.druid.support.jconsole.model.DruidTableCellRenderer) TableColumn(javax.swing.table.TableColumn)

Example 35 with TableColumn

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

the class ColumnGroup method getSize.

/**
     * 取得合并后的单元格的大小,这个方法需要计算,首先 是取得一个没有合并的最小单元格的JTableHeader 的大小
     * 通过Renderer取得组件
     * 
     * @return
     */
public Dimension getSize(JTable table) {
    Component comp = renderer.getTableCellRendererComponent(table, getHeaderValue(), false, false, -1, -1);
    int height = comp.getPreferredSize().height;
    int width = 0;
    // 宽度需要计算合并的还要加上间隙
    Enumeration<Object> enumeration = vector.elements();
    while (enumeration.hasMoreElements()) {
        Object obj = enumeration.nextElement();
        if (obj instanceof TableColumn) {
            TableColumn aColumn = (TableColumn) obj;
            width += aColumn.getWidth();
            width += margin;
        } else {
            width += ((ColumnGroup) obj).getSize(table).width;
        }
    }
    return new Dimension(width, height);
}
Also used : Dimension(java.awt.Dimension) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn)

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