本文整理汇总了Java中javax.swing.table.TableCellRenderer类的典型用法代码示例。如果您正苦于以下问题:Java TableCellRenderer类的具体用法?Java TableCellRenderer怎么用?Java TableCellRenderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TableCellRenderer类属于javax.swing.table包,在下文中一共展示了TableCellRenderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCellRenderer
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
public TableCellRenderer getCellRenderer(int row, int column) {
int modelRow = getRowSorter().convertRowIndexToModel(row);
Double profitPercentage = (Double) getModel().getValueAt(modelRow, 12);
String name = (String) getModel().getValueAt(modelRow, 0);
name = name + " " + portfolio.getTicker(name);
if (profitPercentage != null) {
if (profitPercentage < -10.0) {
return new CellRenderer(java.awt.Color.RED, (column != 0), name);
} else if (profitPercentage < 10.0) {
return new CellRenderer(java.awt.Color.YELLOW, (column != 0), name);
}
}
// return super.getCellRenderer(row, column);
return new CellRenderer(java.awt.Color.GREEN, (column != 0), (column == 0)?name:null);
}
示例2: getCellRenderer
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
public TableCellRenderer getCellRenderer(int row, int column) {
TableColumn tableColumn = getColumnModel().getColumn(column);
TableCellRenderer renderer = tableColumn.getCellRenderer();
if (renderer == null) {
Class<?> c = getColumnClass(column);
if( c.equals(Object.class) )
{
Object o = getValueAt(row,column);
if( o != null )
c = getValueAt(row,column).getClass();
}
renderer = getDefaultRenderer(c);
}
return renderer;
}
示例3: prepareRenderer
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
/** Overridden to hide the selection when not focused, and paint across the
* selected row if focused. */
public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
Object value = getValueAt(row, col);
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
boolean isSelected = isSelected(row, focusOwner);
Component result = renderer.getTableCellRendererComponent(this, value, isSelected, false, row, col);
if( PropUtils.isNimbus ) {
//HACK to get rid of alternate row background colors
if( !isSelected ) {
Color bkColor = getBackground();
if( null != bkColor )
result.setBackground( new Color( bkColor.getRGB() ) );
}
}
return result;
}
示例4: prepareRenderer
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
boolean selected = false;
for(int i: getSelectedRows()) {
if(row == i) {
selected = true;
break;
}
}
Component c = super.prepareRenderer(renderer, row, column);
if(selected) {
c.setBackground(getSelectionBackground());
} else {
c.setBackground(backgroundColorForRow(row));
}
return c;
}
示例5: prepareRenderer
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component c = super.prepareRenderer(renderer, row, column);
if (getModel().hasUpdates(
convertRowIndexToModel(row),
convertColumnIndexToModel(column))) {
Color color = isCellSelected(row, column) ? selectedForeground : unselectedForeground;
if (c instanceof JCheckBox) {
checkboxReplacement.removeAll();
checkboxReplacement.setBorder(new LineBorder(color, borderThickness));
checkboxReplacement.add(c);
return checkboxReplacement;
} else {
c.setForeground(color);
return c;
}
}
return c;
}
示例6: configureTreeCellEditor
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
/**
* Configure the cell editor.
* This method allows to override the configuration of cell editor when cell editing is initiated.
*
* @param editor The editor component
* @param row Editor's row
* @param column Editor's column
*/
protected void configureTreeCellEditor( Component editor, int row, int column ) {
if( !(editor instanceof JComponent) ) {
return;
}
TreeCellEditorBorder b = new TreeCellEditorBorder();
TreePath path = getLayoutCache().getPathForRow(convertRowIndexToModel(row));
Object o = getValueAt(row, column);
RenderDataProvider rdp = getRenderDataProvider();
TableCellRenderer tcr = getDefaultRenderer(Object.class);
if (rdp instanceof CheckRenderDataProvider && tcr instanceof DefaultOutlineCellRenderer) {
CheckRenderDataProvider crender = (CheckRenderDataProvider) rdp;
DefaultOutlineCellRenderer ocr = (DefaultOutlineCellRenderer) tcr;
Object value = getValueAt(row, column);
if (value != null && crender.isCheckable(value) && crender.isCheckEnabled(value)) {
b.checkWidth = ocr.getTheCheckBoxWidth();
b.checkBox = ocr.setUpCheckBox(crender, value, ocr.createCheckBox());
}
}
b.icon = rdp.getIcon(o);
b.nestingDepth = Math.max( 0, path.getPathCount() - (isRootVisible() ? 1 : 2) );
b.isLeaf = getOutlineModel().isLeaf(o);
b.isExpanded = getLayoutCache().isExpanded(path);
((JComponent)editor).setBorder(b);
}
示例7: addColumn
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
public TableColumn addColumn(Object columnIdentifier, int width,
TableCellRenderer renderer,
TableCellEditor editor, List columnData) {
checkDefaultTableModel();
// Set up the model side first
DefaultTableModel m = (DefaultTableModel)getModel();
m.addColumn(columnIdentifier, columnData.toArray());
// The column will have been added to the end, so the index of the
// column in the model is the last element.
TableColumn newColumn = new TableColumn(
m.getColumnCount()-1, width, renderer, editor);
super.addColumn(newColumn);
return newColumn;
}
示例8: getColumnHeaderRenderer
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
/**
* Get the table header renderer for the particular column.
* If the column is {@link ETableColumn}, check createDefaultHeaderRenderer()
* method. If it's not overridden, use the current header renderer.
* If it is overridden, set the current header renderer to the base
* column's renderer. If the overridden renderer delegates to the original,
* it will get this header renderer ({@link #headerRendererUI}).
* @param tc The column
* @return the renderer
*/
private TableCellRenderer getColumnHeaderRenderer(TableColumn tc) {
if (tc instanceof ETableColumn) {
ETableColumn eColumn = (ETableColumn) tc;
TableCellRenderer columnHeaderRenderer;
if (!defaultColumnHeaderRenderers.containsKey(eColumn)) {
TableCellRenderer tcr = eColumn.createDefaultHeaderRenderer();
if (tcr instanceof ETableColumn.ETableColumnHeaderRendererDelegate) {
defaultColumnHeaderRenderers.put(eColumn, null);
columnHeaderRenderer = null;
} else {
eColumn.setTableHeaderRendererDelegate(headerRendererUI);
columnHeaderRenderer = tcr;
}
} else {
columnHeaderRenderer = defaultColumnHeaderRenderers.get(eColumn);
}
if (columnHeaderRenderer != null) {
return columnHeaderRenderer;
} else {
return headerRendererUI;
}
} else {
return headerRendererUI;
}
}
示例9: prepareRenderer
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
@Override
public Component prepareRenderer( TableCellRenderer renderer, int row, int column ) {
SwitcherTableItem item = (SwitcherTableItem) getModel().getValueAt(row, column);
boolean selected = row == getSelectedRow() &&
column == getSelectedColumn() && item != null;
Component renComponent = super.prepareRenderer( renderer, row, column );
if( selected && isClosable( (Item) item) ) {
if( renComponent instanceof JLabel ) {
String text = ((JLabel)renComponent).getText();
if( text.endsWith(" ←") ) { //NOI18N
text = text.substring(0, text.length()-2);
((JLabel)renComponent).setText(text);
}
}
JPanel res = new JPanel( new BorderLayout(0, 0) );
res.add( renComponent, BorderLayout.CENTER );
res.add( btnClose, BorderLayout.EAST );
res.setBackground( renComponent.getBackground() );
return res;
}
return renComponent;
}
示例10: getCellRenderer
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
public TableCellRenderer getCellRenderer(int row, int column) {
Object d = this.getModel().getValueAt(row, column);
/*
* if (d != null) return new JNCalendarCellRenderer( new
* CalendarDate(new Integer(d.toString()).intValue(), _date.getMonth(),
* _date.getYear()));
*/
if (d != null)
renderer.setDate(
new CalendarDate(
new Integer(d.toString()).intValue(),
_date.getMonth(),
_date.getYear()));
else
renderer.setDate(null);
return renderer;
}
示例11: 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);
}
}
示例12: 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;
}
示例13: getCellRenderer
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
/**Returns combobox-styled cellrenderer if a multiple choice cell is to be rendered.
* @return cell renderer*/
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
//if this is type column, I must render it as a combo box instead of a jtextfield
if (column == 1) {
if (isLdEnabled()) {
return LD_enabled_StationTypeCell;
} else {
return LD_disabled_StationTypeCell;
}
} else if (column == getColumnCount() - 1) {
return deleteButtonCellRenderer;
} else {
return new DefaultTableCellRenderer();
}
}
示例14: getTableCellRendererComponent
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Outline outline = (Outline) table;
Node n = getNodeAt(outline, row);
if (n instanceof TreeModelNode) {
TreeModelNode tmn = (TreeModelNode) n;
TableRendererModel trm = tmn.getModel();
try {
if (trm.canRenderCell(tmn.getObject(), columnID)) {
TableCellRenderer renderer = trm.getCellRenderer(tmn.getObject(), columnID);
if (renderer != null) {
return renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
}
} catch (UnknownTypeException ex) {
}
}
// No specific renderer
return defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
示例15: getCellRenderer
import javax.swing.table.TableCellRenderer; //导入依赖的package包/类
/**Returns combobox-styled cellrenderer if a multiple choice cell is to be rendered.
* @return cell renderer*/
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
//if this is type column, I must render it as a combo box instead of a jtextfield
if (column == 1) {
if (LD_enabled_system) {
return LD_enabled_StationTypeCell;
} else {
return LD_disabled_StationTypeCell;
}
} else if (column == getColumnCount() - 1) {
return deleteButtonCellRenderer;
} else {
return new DefaultTableCellRenderer();
}
}