本文整理匯總了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");
}