本文整理匯總了Java中javax.swing.table.TableCellRenderer.getTableCellRendererComponent方法的典型用法代碼示例。如果您正苦於以下問題:Java TableCellRenderer.getTableCellRendererComponent方法的具體用法?Java TableCellRenderer.getTableCellRendererComponent怎麽用?Java TableCellRenderer.getTableCellRendererComponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.table.TableCellRenderer
的用法示例。
在下文中一共展示了TableCellRenderer.getTableCellRendererComponent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: packColumn
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
private static void packColumn(JTable table, int vColIndex, int margin) {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.
getColumnModel();
TableColumn col = colModel.getColumn(vColIndex);
int width; // Obtém a largura do cabeçalho da coluna
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; // Obtém a largura maxima da coluna de dados
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);
}
width += 2 * margin; // Configura a largura
col.setPreferredWidth(width);
}
示例2: initColumnWidth
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
/**
* Initializes preferred (and eventually maximum) width of a table column
* based on the size of its header and the estimated longest value.
*
* @param table Table to adjust the column width for.
* @param index Index of the column.
* @param longValue Estimated long value for the column.
* @param padding Number of pixes for padding.
*/
public static void initColumnWidth(JTable table, int index, Object longValue, int padding) {
TableColumn column = table.getColumnModel().getColumn(index);
// get preferred size of the header
TableCellRenderer headerRenderer = column.getHeaderRenderer();
if (headerRenderer == null) {
headerRenderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = headerRenderer.getTableCellRendererComponent(
table, column.getHeaderValue(), false, false, 0, 0);
int width = comp.getPreferredSize().width;
// get preferred size of the long value (remeber max of the pref. size for header and long value)
comp = table.getDefaultRenderer(table.getModel().getColumnClass(index)).getTableCellRendererComponent(
table, longValue, false, false, 0, index);
width = Math.max(width, comp.getPreferredSize().width) + 2 * padding;
// set preferred width of the column
column.setPreferredWidth(width);
// if the column contains boolean values, the preferred width
// should also be its max width
if (longValue instanceof Boolean) {
column.setMaxWidth(width);
}
}
示例3: pointOutsidePrefSize
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
/**
* Returns true if the given point is outside the preferredSize of the
* item at the given row of the table. (Column must be 0).
* Does not check the "Table.isFileList" property. That should be checked
* before calling this method.
* This is used to make Windows {@literal L&F} JFileChooser act
* like native dialogs.
*/
public static boolean pointOutsidePrefSize(JTable table, int row, int column, Point p) {
if (table.convertColumnIndexToModel(column) != 0 || row == -1) {
return true;
}
TableCellRenderer tcr = table.getCellRenderer(row, column);
Object value = table.getValueAt(row, column);
Component cell = tcr.getTableCellRendererComponent(table, value, false,
false, row, column);
Dimension itemSize = cell.getPreferredSize();
Rectangle cellBounds = table.getCellRect(row, column, false);
cellBounds.width = itemSize.width;
cellBounds.height = itemSize.height;
// See if coords are inside
// ASSUME: mouse x,y will never be < cell's x,y
assert (p.x >= cellBounds.x && p.y >= cellBounds.y);
return p.x > cellBounds.x + cellBounds.width ||
p.y > cellBounds.y + cellBounds.height;
}
示例4: isUsed
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
/** Returns true if source root is used for debugging and false otherwise.
* @param source source root
* @return true if source root is used for debugging; false otherwise
*/
public boolean isUsed(String source) {
int row = treeTable().findCellRow(source);
// gets component used to render a value
TableCellRenderer renderer = treeTable().getCellRenderer(row, 1);
Component comp = renderer.getTableCellRendererComponent(
(JTable)treeTable().getSource(),
treeTable().getValueAt(row, 1),
false,
false,
row,
1
);
String tooltip = new JComponentOperator((JComponent)comp).getToolTipText();
return "true".equalsIgnoreCase(tooltip);
}
示例5: getTextAt
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
/**
* Renvoie le texte à la position demandée.
* @return String
* @param row int
* @param column int
*/
private String getTextAt(int row, int column) {
final Object value = getModel().getValueAt(row, column);
String text = "";
if (value != null) {
final int columnIndex = convertColumnIndexToView(column);
final TableCellRenderer renderer = getCellRenderer(row, columnIndex);
final java.awt.Component rendererComponent = renderer
.getTableCellRendererComponent(this, value, false, false, row, columnIndex);
text = getTextFrom(value, rendererComponent);
if (text == null) {
text = "";
}
}
return text;
}
示例6: getTableCellRendererComponent
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
TableCellRenderer tableCellRenderer = table.getTableHeader().getDefaultRenderer();
Component c = tableCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (c instanceof JLabel) {
JLabel l = (JLabel) c;
if (column == sortingColumn) { // only for sorting column the icon is displayed
l.setIcon((sortOrder == SortableTableModel.SORT_ORDER_ASC) ? ascIcon : descIcon);
l.setFont(l.getFont().deriveFont(Font.BOLD));
} else {
l.setIcon(null);
}
l.setHorizontalTextPosition(JLabel.LEFT);
}
return c;
}
示例7: getTableCellRendererComponent
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Component component = super.getTableCellRendererComponent(table,
value, isSelected, hasFocus, row, column);
if (value != null) {
if (component instanceof JLabel)
((JLabel) component)
.setText(DateAttributePlugin.DATE_INSTANCE
.format(value));
else {
TableCellRenderer renderer = table
.getDefaultRenderer(Date.class);
return renderer.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
}
}
return component;
}
示例8: autoSizeTableColumns
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
public static void autoSizeTableColumns(JTable table) {
TableModel model = table.getModel();
TableColumn column = null;
Component comp = null;
int headerWidth = 0;
int maxCellWidth = Integer.MIN_VALUE;
int cellWidth = 0;
TableCellRenderer headerRenderer =
table.getTableHeader().getDefaultRenderer();
for (int i = 0; i < table.getColumnCount(); i++) {
column = table.getColumnModel().getColumn(i);
comp = headerRenderer.getTableCellRendererComponent(table,
column.getHeaderValue(), false, false, 0, 0);
headerWidth = comp.getPreferredSize().width + 10;
maxCellWidth = Integer.MIN_VALUE;
for (int j = 0; j < Math.min(model.getRowCount(), 30); j++) {
TableCellRenderer r = table.getCellRenderer(j, i);
comp = r.getTableCellRendererComponent(table,
model.getValueAt(j, i),
false, false, j, i);
cellWidth = comp.getPreferredSize().width;
if (cellWidth >= maxCellWidth) {
maxCellWidth = cellWidth;
}
}
column.setPreferredWidth(Math.max(headerWidth, maxCellWidth)
+ 10);
}
}
示例9: initColumnSizes
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
/**
* This method picks good column sizes. If all column headers are wider than
* the column's cells' contents, then just use column.sizeWidthToFit().
* @param table JTable
*/
public void initColumnSizes(JTable table) {
TableColumn column;
Component comp;
int headerWidth;
int cellWidth;
TableCellRenderer headerRenderer = table.getTableHeader()
.getDefaultRenderer();
// TODO: move to tableModel. AK
for (int i = 0; i < this.pdfDefinitionTableModel.getColumnCount(); i++) {
column = table.getColumnModel().getColumn(i);
comp = headerRenderer.getTableCellRendererComponent(null, column
.getHeaderValue(), false, false, 0, 0);
headerWidth = comp.getPreferredSize().width;
// TODO: move to tableModel. AK
comp = table.getDefaultRenderer(this.pdfDefinitionTableModel.getColumnClass(i))
.getTableCellRendererComponent(table, this.pdfDefinitionTableModel.longValues[i], false,
false, 0, i);
cellWidth = comp.getPreferredSize().width;
// XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
column.setPreferredWidth(Math.max(headerWidth, cellWidth));
}
}
示例10: getTableCellRendererComponent
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
TableCellRenderer rend = value == null || !table.getModel().isCellEditable(row, column)
? label : checkbox;
// reset value in case the cell is not editable
value = value != null && rend == label ? null : value;
Component comp = rend.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
return comp;
}
示例11: initColumnSizes
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
private void initColumnSizes(JTable table) {
MyTableModel model = (MyTableModel) table.getModel();
TableColumn column = null;
Component comp = null;
int headerWidth = 0;
int cellWidth = 0;
Object[] longValues = model.longValues;
TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer();
for (int i = 0; i < 5; i++) {
column = table.getColumnModel().getColumn(i);
comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);
headerWidth = comp.getPreferredSize().width;
comp = table.getDefaultRenderer(model.getColumnClass(i)).getTableCellRendererComponent(table, longValues[i], false,
false, 0, i);
cellWidth = comp.getPreferredSize().width;
if (DEBUG) {
System.out.println(
"Initializing width of column " + i + ". " + "headerWidth = " + headerWidth + "; cellWidth = " + cellWidth);
}
column.setPreferredWidth(Math.max(headerWidth, cellWidth));
}
}
示例12: getTableCellRendererComponent
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
TableCellRenderer def = table.getDefaultRenderer(table.getColumnClass(column));
if (!table.isEnabled()) {
isSelected = hasFocus = false;
}
JComponent c = (JComponent)def.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
c.setEnabled(table.isEnabled());
return c;
}
示例13: getValueAt
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
@Override
public Object getValueAt(Object node, int index) {
TreeTableNode tableRow = (TreeTableNode) node;
if (tableRow instanceof GroupNode) {
if (index == 0) {
GroupNode groupNode = (GroupNode) tableRow;
if (table != null) {
Attribute attribute = groupNode.getAttribute();
if (attribute != null) {
AttributePlugin plugin = framework
.findAttributePlugin(attribute);
TableCellRenderer renderer = plugin
.getTableCellRenderer(rowSet.getEngine(),
framework.getAccessRules(), attribute);
if (renderer != null) {
try {
Component c = renderer
.getTableCellRendererComponent(table,
groupNode.getValue(), false,
false, -1, -1);
if (c instanceof JLabel)
return ((JLabel) c).getText();
} catch (Exception e) {
// e.printStackTrace();
}
}
}
}
return groupNode.getValue();
}
return null;
}
return localizers[index].getValue(valueGetters[index].getValue(
tableRow, index));
}
示例14: getRendererComponent
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
public static Component getRendererComponent(JTableHeader jTableHeader, int item) {
int columnCount = jTableHeader.getColumnModel().getColumnCount();
if (item < 0 || item >= columnCount) {
throw new NoSuchElementException("Index out of bounds error on JTableHeader: " + item, null);
}
Object headerValue = jTableHeader.getColumnModel().getColumn(item).getHeaderValue();
TableCellRenderer headerRenderer = jTableHeader.getColumnModel().getColumn(item).getHeaderRenderer();
if (headerRenderer == null) {
headerRenderer = jTableHeader.getDefaultRenderer();
}
Component rendererComponent = headerRenderer.getTableCellRendererComponent(jTableHeader.getTable(), headerValue, false,
false, 0, item);
return rendererComponent;
}
示例15: getHeaderHeight
import javax.swing.table.TableCellRenderer; //導入方法依賴的package包/類
/**
* Calculate and return the height of the header.
*
* @return Header Height
*/
@SuppressWarnings("unchecked")
private int getHeaderHeight() {
int height = 0;
GroupableTableColumnModel columnModel = (GroupableTableColumnModel) header
.getColumnModel();
for (int column = 0; column < columnModel.getColumnCount(); column++) {
TableColumn aColumn = columnModel.getColumn(column);
TableCellRenderer renderer = aColumn.getHeaderRenderer();
if (renderer == null) {
renderer = header.getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(header
.getTable(), aColumn.getHeaderValue(), false, false, -1,
column);
int cHeight = comp.getPreferredSize().height;
Iterator iter = columnModel.getColumnGroups(aColumn);
if (iter != null) {
while (iter.hasNext()) {
ColumnGroup cGroup = (ColumnGroup) iter.next();
cHeight += cGroup.getSize(header.getTable()).height;
}
}
height = Math.max(height, cHeight);
}
return height;
}