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