本文整理了Java中javax.swing.table.TableCellRenderer.getTableCellRendererComponent()
方法的一些代码示例,展示了TableCellRenderer.getTableCellRendererComponent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TableCellRenderer.getTableCellRendererComponent()
方法的具体详情如下:
包路径:javax.swing.table.TableCellRenderer
类名称:TableCellRenderer
方法名:getTableCellRendererComponent
暂无
代码示例来源:origin: alibaba/druid
/**
* 取得合并后的单元格的大小,这个方法需要计算,首先 是取得一个没有合并的最小单元格的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);
}
代码示例来源:origin: alibaba/druid
Component comp = renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false,
false, -1, column);
int cHeight = comp.getPreferredSize().height;
代码示例来源:origin: alibaba/druid
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);
}
代码示例来源:origin: alibaba/druid
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);
}
代码示例来源:origin: groovy/groovy-core
tcr = table.getDefaultRenderer(table.getColumnClass(column));
children.add(tcr.getTableCellRendererComponent(table, value, selected, focused, row, column));
} else if (tree != null) {
TreeCellRenderer tcr;
代码示例来源:origin: ron190/jsql-injection
/**
* Calculated the width based on the column name
*/
private int getColumnHeaderWidth(int column) {
if (! this.isColumnHeaderIncluded) {
return 0;
}
TableColumn tableColumn = this.tableAdjust.getColumnModel().getColumn(column);
Object value = tableColumn.getHeaderValue();
TableCellRenderer renderer = tableColumn.getHeaderRenderer();
if (renderer == null) {
renderer = this.tableAdjust.getTableHeader().getDefaultRenderer();
}
Component c = renderer.getTableCellRendererComponent(this.tableAdjust, value, false, false, -1, column);
return c.getPreferredSize().width;
}
代码示例来源:origin: com.alibaba/druid
/**
* 取得合并后的单元格的大小,这个方法需要计算,首先 是取得一个没有合并的最小单元格的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);
}
代码示例来源:origin: ron190/jsql-injection
/**
* Specify the table and spacing
*/
public AdjusterTableColumn(JTable tableAdjust, int spacing) {
this.tableAdjust = tableAdjust;
final TableCellRenderer tcrOs = tableAdjust.getTableHeader().getDefaultRenderer();
tableAdjust.getTableHeader().setDefaultRenderer(
(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) -> {
JLabel lbl = (JLabel) tcrOs.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column
);
lbl.setBackground(new Color(230, 230, 230));
return lbl;
});
this.spacing = spacing;
this.setColumnHeaderIncluded( true );
this.setColumnDataIncluded( true );
this.setOnlyAdjustLarger( true );
this.setDynamicAdjustment( false );
this.installActions();
}
代码示例来源:origin: stackoverflow.com
TableCellRenderer cellRenderer = jTable.getCellRenderer(row, column);
Object valueAt = jTable.getValueAt(row, column);
Component tableCellRendererComponent = cellRenderer.getTableCellRendererComponent(jTable, valueAt, false, false, row, column);
int heightPreferable = tableCellRendererComponent.getPreferredSize().height;
maxHeight = Math.max(heightPreferable, maxHeight);
renderer = table.getTableHeader().getDefaultRenderer();
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width;
comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, column), false, false, r, column);
int currentWidth = comp.getPreferredSize().width;
width = Math.max(width, currentWidth);
代码示例来源:origin: stackoverflow.com
@Override
public Component getTableCellRendererComponent(JTable jTable, Object o, boolean b, boolean b1, int row, int column) {
JLabel parent = (JLabel) defaultRenderer.getTableCellRendererComponent(jTable, o, b, b1, row, column);
if (column == 0) {
parent.setText("name");
TableCellRenderer cellRenderer = jTable.getCellRenderer(row, column);
Object valueAt = jTable.getValueAt(row, column);
Component tableCellRendererComponent = cellRenderer.getTableCellRendererComponent(jTable, valueAt, false, false, row, column);
int heightPreferable = tableCellRendererComponent.getPreferredSize().height;
maxHeight = Math.max(heightPreferable, maxHeight);
renderer = table.getTableHeader().getDefaultRenderer();
Component comp = renderer.getTableCellRendererComponent(
table, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width;
comp = renderer.getTableCellRendererComponent(
table, table.getValueAt(r, column), false, false, r, column);
int currentWidth = comp.getPreferredSize().width;
代码示例来源:origin: stackoverflow.com
renderer = table.getTableHeader().getDefaultRenderer();
Component comp = renderer.getTableCellRendererComponent(table, getHeaderValue() == null || getHeaderValue().trim().isEmpty() ? " "
: getHeaderValue(), false, false, -1, -1);
int height = comp.getPreferredSize().height;
代码示例来源:origin: com.alibaba/druid
Component comp = renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false,
false, -1, column);
int cHeight = comp.getPreferredSize().height;
代码示例来源:origin: com.alibaba/druid
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);
}
代码示例来源:origin: com.alibaba/druid
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);
}
代码示例来源:origin: pentaho/mondrian
for (int i = 0; i < relationTable.getRowCount(); i++) {
TableCellRenderer renderer = relationTable.getCellRenderer(i, 1);
Component comp = renderer.getTableCellRendererComponent(
relationTable,
relationTable.getValueAt(i, 1),
代码示例来源:origin: stackoverflow.com
Component component = table.getTableHeader().getDefaultRenderer().getTableCellRendererComponent(table, value, false, false, -1, -2);
((JLabel) component).setHorizontalAlignment(SwingConstants.CENTER);
if (selected) {
代码示例来源:origin: ron190/jsql-injection
this.tableValues.getTableHeader().setDefaultRenderer(
(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) -> {
JLabel label = (JLabel) cellRendererHeader.getTableCellRendererComponent(
table, StringUtil.detectUtf8HtmlNoWrap(" "+ value +" "), isSelected, hasFocus, row, column
);
代码示例来源:origin: stackoverflow.com
renderer = getHeader().getDefaultRenderer();
Component c = renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false,
-1, columnIndex);
Component component = renderer.getTableCellRendererComponent(header.getTable(), cGroup.getHeaderValue(), false,
false, -1, -1);
rendererPane
Component comp = renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false,
false, -1, column);
int cHeight = comp.getPreferredSize().height;
代码示例来源:origin: ron190/jsql-injection
this.networkTable.getTableHeader().setDefaultRenderer(
(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) -> {
JLabel lbl = (JLabel) tcrOs.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
lbl.setBorder(
BorderFactory.createCompoundBorder(
代码示例来源:origin: pentaho/mondrian
TableCellRenderer renderer = propertyTable.getCellRenderer(i, 1);
Component comp =
renderer.getTableCellRendererComponent(
propertyTable,
propertyTable.getValueAt(i, 1),
内容来源于网络,如有侵权,请联系作者删除!