use of javax.swing.table.TableCellRenderer in project gitblit by gitblit.
the class Utils method packColumn.
// Sets the preferred width of the visible column specified by vColIndex.
// The column will be just wide enough to show the column head and the
// widest cell in the column. margin pixels are added to the left and right
// (resulting in an additional width of 2*margin pixels).
private static void packColumn(JTable table, int vColIndex, int margin) {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
TableColumn col = colModel.getColumn(vColIndex);
int width = 0;
// Get width of column header
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width;
// Get maximum width of column data
for (int r = 0; r < table.getRowCount(); r++) {
renderer = table.getCellRenderer(r, vColIndex);
comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex), false, false, r, vColIndex);
width = Math.max(width, comp.getPreferredSize().width);
}
// Add margin
width += 2 * margin;
// Set the width
col.setPreferredWidth(width);
}
use of javax.swing.table.TableCellRenderer in project gephi by gephi.
the class AbstractElementsDataTable method prepareRenderers.
private void prepareRenderers() {
for (Class<?> typeClass : AttributeUtils.getSupportedTypes()) {
TableCellRenderer typeRenderer = null;
boolean isNumberType = AttributeUtils.isNumberType(typeClass);
boolean isDynamic = AttributeUtils.isDynamicType(typeClass);
boolean isArray = typeClass.isArray();
if (typeClass.equals(IntervalSet.class)) {
typeRenderer = drawTimeIntervalGraphics ? intervalSetGraphicsRenderer : timeSetRenderer;
} else if (typeClass.equals(TimestampSet.class)) {
typeRenderer = drawTimeIntervalGraphics ? timestampSetGraphicsRenderer : timeSetRenderer;
} else if (drawSparklines && isNumberType && (isArray || isDynamic)) {
if (isArray) {
typeRenderer = arraySparklinesGraphicsRenderer;
} else if (IntervalMap.class.isAssignableFrom(typeClass)) {
typeRenderer = intervalMapSparklinesGraphicsRenderer;
} else if (TimestampMap.class.isAssignableFrom(typeClass)) {
typeRenderer = timestampMapSparklinesGraphicsRenderer;
}
}
if (typeRenderer == null) {
if (isArray) {
typeRenderer = arrayRenderer;
} else if (isDynamic) {
typeRenderer = timeMapRenderer;
} else if (isNumberType) {
boolean isDecimalType = typeClass.equals(Double.class) || typeClass.equals(double.class) || typeClass.equals(Float.class) || typeClass.equals(float.class);
if (isDecimalType) {
typeRenderer = doubleRenderer;
}
}
}
if (typeRenderer == null) {
typeRenderer = defaultStringRepresentationRenderer;
}
//For any other type, use our own cell renderer that shows the values with standard, not locale specific toString methods
if (!typeClass.equals(Boolean.class) && !typeClass.equals(boolean.class)) {
table.setDefaultRenderer(typeClass, typeRenderer);
}
}
}
use of javax.swing.table.TableCellRenderer in project binnavi by google.
the class CTableSorter method setTableHeader.
public void setTableHeader(final JTableHeader tableHeader) {
if (this.tableHeader != null) {
this.tableHeader.removeMouseListener(mouseListener);
final TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();
if (defaultRenderer instanceof SortableHeaderRenderer) {
this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);
}
}
this.tableHeader = tableHeader;
if (this.tableHeader != null) {
this.tableHeader.addMouseListener(mouseListener);
this.tableHeader.setDefaultRenderer(new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer()));
}
}
use of javax.swing.table.TableCellRenderer in project druid by alibaba.
the class GroupableTableHeaderUI method getHeaderHeight.
public int getHeaderHeight() {
int height = 0;
TableColumnModel columnModel = header.getColumnModel();
for (int column = 0; column < columnModel.getColumnCount(); column++) {
TableColumn aColumn = columnModel.getColumn(column);
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;
}
};
}
Component comp = renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false, -1, column);
int cHeight = comp.getPreferredSize().height;
Enumeration<ColumnGroup> enumeration = ((GroupableTableHeader) header).getColumnGroups(aColumn);
if (enumeration != null) {
while (enumeration.hasMoreElements()) {
ColumnGroup cGroup = (ColumnGroup) enumeration.nextElement();
cHeight += cGroup.getSize(header.getTable()).height;
}
}
height = Math.max(height, cHeight);
}
height = Math.max(height, m_height);
return height;
}
use of javax.swing.table.TableCellRenderer in project EnrichmentMapApp by BaderLab.
the class DataSetSelector method getTable.
private JTable getTable() {
if (table == null) {
final DefaultSelectorTableCellRenderer defRenderer = new DefaultSelectorTableCellRenderer();
final CheckBoxTableCellRenderer checkBoxRenderer = new CheckBoxTableCellRenderer();
table = new JTable(new DefaultTableModel(HEARDER_NAMES, 0)) {
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
if (column == SELECTED_COL_IDX)
return checkBoxRenderer;
return defRenderer;
}
};
table.setTableHeader(null);
table.setShowGrid(false);
JTextField tmpField = new JTextField();
makeSmall(tmpField);
table.setRowHeight(Math.max(table.getRowHeight(), tmpField.getPreferredSize().height - 4));
table.setIntercellSpacing(new Dimension(0, 1));
table.getSelectionModel().addListSelectionListener(e -> {
if (!e.getValueIsAdjusting()) {
updateRemoveButton();
if (table.getSelectedRowCount() > 0)
previousSelectedRows = Arrays.stream(table.getSelectedRows()).boxed().collect(Collectors.toList());
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
final boolean isMac = LookAndFeelUtil.isMac();
// COMMAND button down on MacOS (or CONTROL button down on another OS) or SHIFT?
if ((isMac && e.isMetaDown()) || (!isMac && e.isControlDown()) || e.isShiftDown())
// Ignore!
return;
final int col = table.columnAtPoint(e.getPoint());
if (col == SELECTED_COL_IDX) {
final int row = table.rowAtPoint(e.getPoint());
// Restore previous multiple-row selection first
if (previousSelectedRows != null && previousSelectedRows.contains(row)) {
for (int i : previousSelectedRows) table.addRowSelectionInterval(i, i);
}
toggleChecked(row);
}
}
});
}
return table;
}
Aggregations