本文整理汇总了Java中javax.swing.table.DefaultTableCellRenderer.setForeground方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultTableCellRenderer.setForeground方法的具体用法?Java DefaultTableCellRenderer.setForeground怎么用?Java DefaultTableCellRenderer.setForeground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.table.DefaultTableCellRenderer
的用法示例。
在下文中一共展示了DefaultTableCellRenderer.setForeground方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCellRenderer
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
/**
* This method sets read write rows to be blue, and other rows to be their
* default rendered colour.
*/
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
DefaultTableCellRenderer tcr =
(DefaultTableCellRenderer) super.getCellRenderer(row,column);
tcr.setToolTipText(getToolTip(row,column));
if (defaultColor == null) {
defaultColor = tcr.getForeground();
editableColor = Color.blue;
errorColor = Color.red;
// this sometimes happens for some reason
if (defaultColor == null) {
return tcr;
}
}
if (column != VALUE_COLUMN) {
tcr.setForeground(defaultColor);
return tcr;
}
if (isCellError(row,column)) {
tcr.setForeground(errorColor);
} else if (isCellEditable(row, column)) {
tcr.setForeground(editableColor);
} else {
tcr.setForeground(defaultColor);
}
return tcr;
}
示例2: initialiseRenderer
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
private void initialiseRenderer(int modelColumnIndex, Color color) {
if (modelColumnIndex < 0) {
return;
}
int viewColumnIndex = table.convertColumnIndexToView(modelColumnIndex);
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setHorizontalAlignment(JLabel.CENTER);
if (color != null) {
renderer.setForeground(color);
}
table.getColumnModel().getColumn(viewColumnIndex).setCellRenderer(renderer);;
}
示例3: setCellForeground
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
public void setCellForeground(Color color, int columnindex) {
if (columnindex < 0 || columnindex >= getColumnCount())
return;
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
TableColumn column = jtable.getTableHeader().getColumnModel()
.getColumn(columnindex);
renderer.setForeground(color);
column.setCellRenderer(renderer);
}
示例4: testTableUnSelectedDoNothingHighlighter
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
/**
* Issue #258-swingx: DefaultTableCellRenderer has memory.
* How to formulate as test?
* this is testing the hack (reset the memory in ResetDTCR to null), not
* any highlighter!
*/
public void testTableUnSelectedDoNothingHighlighter() {
JXTable table = new JXTable(10, 2);
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setForeground(foreground);
table.setHighlighters(new ColorHighlighter());
Component comp = table.prepareRenderer(renderer, 0, 0);
assertEquals("do nothing highlighter must not change foreground", foreground, comp.getForeground());
fail("testing the hack around DefaultTableCellRenderer memory - not the memory itself");
}
示例5: interactiveTableCustomCoreRendererColor
import javax.swing.table.DefaultTableCellRenderer; //导入方法依赖的package包/类
/**
* Issue #258-swingx: Background LegacyHighlighter must not change custom
* foreground.
* <p>
*
* Visualizing effect of hack: table-internally, a ResetDTCRColorHighlighter
* tries to neutralize DefaultTableCellRenderer's color memory.
*
* <ul>
* <li> a DTCR with custom foreground and custom background
* <li> the renderer is shared between a table with background highlighter
* (alternateRowHighlighter) and a table without highlighter
* <li> the custom foreground must show in both
* <li> the custom background must show in the table without highlighter
* <li> the custom background must not show in the table with highlighter
* (AlternateRowHighlighter overwrite both striped and unstriped back)
* </ul>
*
*/
public void interactiveTableCustomCoreRendererColor() {
TableModel model = new AncientSwingTeam();
JXTable table = new JXTable(model);
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setForeground(foreground);
renderer.setBackground(background);
table.addHighlighter(
HighlighterFactory.createSimpleStriping(HighlighterFactory.GENERIC_GRAY));
table.setDefaultRenderer(Object.class, renderer);
JXTable nohighlight = new JXTable(model);
nohighlight.setDefaultRenderer(Object.class, renderer);
showWithScrollingInFrame(table, nohighlight,
"core: custom colored renderer with bg highlighter <--> shared without highl");
}