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;
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations