use of javax.swing.table.DefaultTableCellRenderer in project intellij-community by JetBrains.
the class SwingHelper method setNoBorderCellRendererFor.
public static void setNoBorderCellRendererFor(@NotNull TableColumn column) {
final TableCellRenderer previous = column.getCellRenderer();
column.setCellRenderer(new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component component;
if (previous != null) {
component = previous.getTableCellRendererComponent(table, value, isSelected, false, row, column);
} else {
component = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
}
if (component instanceof JComponent) {
((JComponent) component).setBorder(null);
}
return component;
}
});
}
use of javax.swing.table.DefaultTableCellRenderer in project android by JetBrains.
the class IconPickerDialogTest method tableToString.
@NotNull
public static String tableToString(@NotNull JTable table, int startRow, int endRow, int startColumn, int endColumn, int cellWidth) {
StringBuilder sb = new StringBuilder();
String formatString = "%-" + Integer.toString(cellWidth) + "s";
for (int row = Math.max(0, startRow); row < Math.min(endRow, table.getRowCount()); row++) {
for (int column = Math.max(0, startColumn); column < Math.min(table.getColumnCount(), endColumn); column++) {
Object value = table.getValueAt(row, column);
TableCellRenderer renderer = table.getCellRenderer(row, column);
Component component = renderer.getTableCellRendererComponent(table, value, false, false, row, column);
DefaultTableCellRenderer label = (DefaultTableCellRenderer) component;
assertThat(label.getText()).isEmpty();
String cell = label.getAccessibleContext().getAccessibleName();
if (cell.length() > cellWidth) {
cell = cell.substring(0, cellWidth - 3) + "...";
}
sb.append(String.format(formatString, cell));
}
sb.append('\n');
}
return sb.toString();
}
use of javax.swing.table.DefaultTableCellRenderer in project jabref by JabRef.
the class MainTable method getCellRenderer.
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
int score = -3;
DefaultTableCellRenderer renderer = MainTable.defRenderer;
if ((model.getSearchState() != MainTableDataModel.DisplayOption.FLOAT) || matches(row, SearchMatcher.INSTANCE)) {
score++;
}
if ((model.getGroupingState() != MainTableDataModel.DisplayOption.FLOAT) || matches(row, GroupMatcher.INSTANCE)) {
score += 2;
}
// a very grayed out one for entries with -2
if (score < -1) {
if (column == 0) {
MainTable.veryGrayedOutNumberRenderer.setNumber(row);
renderer = MainTable.veryGrayedOutNumberRenderer;
} else {
renderer = MainTable.veryGrayedOutRenderer;
}
} else if (score == -1) {
if (column == 0) {
MainTable.grayedOutNumberRenderer.setNumber(row);
renderer = MainTable.grayedOutNumberRenderer;
} else {
renderer = MainTable.grayedOutRenderer;
}
} else if (column == 0) {
if (isComplete(row)) {
MainTable.compRenderer.setNumber(row);
int marking = isMarked(row);
if (marking > 0) {
marking = Math.min(marking, EntryMarker.MARK_COLOR_LEVELS);
renderer = MainTable.markedNumberRenderers.get(marking - 1);
MainTable.markedNumberRenderers.get(marking - 1).setNumber(row);
} else {
renderer = MainTable.compRenderer;
}
} else {
// Return a renderer with red background if the entry is incomplete.
MainTable.incRenderer.setNumber(row);
renderer = MainTable.incRenderer;
}
} else if (tableColorCodes || tableResolvedColorCodes) {
CellRendererMode status = getCellStatus(row, column, tableResolvedColorCodes);
if (status == CellRendererMode.REQUIRED) {
renderer = MainTable.reqRenderer;
} else if (status == CellRendererMode.OPTIONAL) {
renderer = MainTable.optRenderer;
} else if (status == CellRendererMode.RESOLVED) {
renderer = MainTable.resolvedRenderer;
}
}
// For MARKED feature:
int marking = isMarked(row);
if ((column != 0) && (marking > 0)) {
marking = Math.min(marking, EntryMarker.MARK_COLOR_LEVELS);
renderer = MainTable.markedRenderers.get(marking - 1);
}
return renderer;
}
use of javax.swing.table.DefaultTableCellRenderer in project adempiere by adempiere.
the class ResultTable method autoSize.
/**************************************************************************
* Size Columns
*/
private void autoSize() {
log.config("");
//
// making sure it fits in a column
final int SLACK = 8;
// max size of a column
final int MAXSIZE = 300;
//
TableColumnModel tcm = getColumnModel();
// For all columns
for (int col = 0; col < tcm.getColumnCount(); col++) {
TableColumn tc = tcm.getColumn(col);
// log.config( "Column=" + col, tc.getHeaderValue());
int width = 0;
// Header
TableCellRenderer renderer = tc.getHeaderRenderer();
if (renderer == null)
renderer = new DefaultTableCellRenderer();
Component comp = renderer.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, 0);
// log.fine( "Hdr - preferred=" + comp.getPreferredSize().width + ", width=" + comp.getWidth());
width = comp.getPreferredSize().width + SLACK;
// Cells
// first 30 rows
int maxRow = Math.min(30, getRowCount());
for (int row = 0; row < maxRow; row++) {
renderer = getCellRenderer(row, col);
comp = renderer.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col);
int rowWidth = comp.getPreferredSize().width + SLACK;
width = Math.max(width, rowWidth);
}
// Width not greater ..
width = Math.min(MAXSIZE, width);
tc.setPreferredWidth(width);
// log.fine( "width=" + width);
}
// for all columns
}
use of javax.swing.table.DefaultTableCellRenderer in project adempiere by adempiere.
the class MiniTable method autoSize.
/**
* Size Columns.
* Uses Mimimum Column Size
*/
public void autoSize() {
if (!autoResize)
return;
long start = System.currentTimeMillis();
//
// making sure it fits in a column
final int SLACK = 8;
// max size of a column
final int MAXSIZE = 300;
//
TableModel model = this.getModel();
int size = model.getColumnCount();
// for all columns
for (int col = 0; col < size; col++) {
// Column & minimum width
TableColumn tc = this.getColumnModel().getColumn(col);
int width = 0;
if (m_minWidth.size() > col)
width = ((Integer) m_minWidth.get(col)).intValue();
// log.config( "Column=" + col + " " + column.getHeaderValue());
// Header
TableCellRenderer renderer = tc.getHeaderRenderer();
if (renderer == null)
renderer = new DefaultTableCellRenderer();
Component comp = renderer.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, 0);
// log.fine( "Hdr - preferred=" + comp.getPreferredSize().width + ", width=" + comp.getWidth());
width = Math.max(width, comp.getPreferredSize().width + SLACK);
// Cells
// first 30 rows
int maxRow = Math.min(30, getRowCount());
for (int row = 0; row < maxRow; row++) {
renderer = getCellRenderer(row, col);
comp = renderer.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col);
if (comp != null) {
int rowWidth = comp.getPreferredSize().width + SLACK;
width = Math.max(width, rowWidth);
}
}
// Width not greater ..
width = Math.min(MAXSIZE, width);
tc.setPreferredWidth(width);
// log.fine( "width=" + width);
}
// for all columns
log.finer("Cols=" + size + " - " + (System.currentTimeMillis() - start) + "ms");
}
Aggregations