use of javax.swing.table.TableColumn in project druid by alibaba.
the class GroupableTableHeaderUI method getPreferredSize.
@Override
public Dimension getPreferredSize(JComponent c) {
long width = 0;
Enumeration<TableColumn> enumeration = header.getColumnModel().getColumns();
while (enumeration.hasMoreElements()) {
TableColumn aColumn = enumeration.nextElement();
width = width + aColumn.getWidth();
}
return createHeaderSize(width);
}
use of javax.swing.table.TableColumn 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.TableColumn in project intellij-community by JetBrains.
the class BaseTableView method store.
public static void store(final Storage storage, final JTable table) {
final TableColumnModel model = table.getTableHeader().getColumnModel();
final int columnCount = model.getColumnCount();
final boolean[] storedColumns = new boolean[columnCount];
Arrays.fill(storedColumns, false);
for (int i = 0; i < columnCount; i++) {
final TableColumn column = model.getColumn(i);
storage.put(widthPropertyName(i), String.valueOf(column.getWidth()));
final int modelIndex = column.getModelIndex();
storage.put(orderPropertyName(i), String.valueOf(modelIndex));
if (storedColumns[modelIndex]) {
LOG.error("columnCount: " + columnCount + " current: " + i + " modelINdex: " + modelIndex);
}
storedColumns[modelIndex] = true;
}
}
use of javax.swing.table.TableColumn in project intellij-community by JetBrains.
the class OrderPanel method setCheckboxColumnName.
public void setCheckboxColumnName(final String name) {
TableColumn checkboxColumn = myEntryTable.getColumnModel().getColumn(getCheckboxColumn());
if (StringUtil.isEmpty(name)) {
CHECKBOX_COLUMN_NAME = "";
TableUtil.setupCheckboxColumn(checkboxColumn);
} else {
CHECKBOX_COLUMN_NAME = name;
final FontMetrics fontMetrics = myEntryTable.getFontMetrics(myEntryTable.getFont());
final int width = fontMetrics.stringWidth(" " + name + " ") + 4;
checkboxColumn.setWidth(width);
checkboxColumn.setPreferredWidth(width);
checkboxColumn.setMaxWidth(width);
checkboxColumn.setMinWidth(width);
}
}
use of javax.swing.table.TableColumn in project intellij-community by JetBrains.
the class DarculaTableHeaderUI method paint.
@Override
public void paint(Graphics g2, JComponent c) {
final Graphics2D g = (Graphics2D) g2;
final GraphicsConfig config = new GraphicsConfig(g);
final Color bg = c.getBackground();
g.setPaint(new GradientPaint(0, 0, ColorUtil.shift(bg, 1.4), 0, c.getHeight(), ColorUtil.shift(bg, 0.9)));
final int h = c.getHeight();
final int w = c.getWidth();
g.fillRect(0, 0, w, h);
g.setPaint(ColorUtil.shift(bg, 0.75));
g.drawLine(0, h - 1, w, h - 1);
g.drawLine(w - 1, 0, w - 1, h - 1);
final Enumeration<TableColumn> columns = ((JTableHeader) c).getColumnModel().getColumns();
final Color lineColor = ColorUtil.shift(bg, 0.7);
final Color shadow = Gray._255.withAlpha(30);
int offset = 0;
while (columns.hasMoreElements()) {
final TableColumn column = columns.nextElement();
if (columns.hasMoreElements() && column.getWidth() > 0) {
offset += column.getWidth();
g.setColor(lineColor);
g.drawLine(offset - 1, 1, offset - 1, h - 3);
g.setColor(shadow);
g.drawLine(offset, 1, offset, h - 3);
}
}
config.restore();
super.paint(g, c);
}
Aggregations