本文整理匯總了Java中javax.swing.tree.DefaultTreeCellRenderer.setTextNonSelectionColor方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultTreeCellRenderer.setTextNonSelectionColor方法的具體用法?Java DefaultTreeCellRenderer.setTextNonSelectionColor怎麽用?Java DefaultTreeCellRenderer.setTextNonSelectionColor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.tree.DefaultTreeCellRenderer
的用法示例。
在下文中一共展示了DefaultTreeCellRenderer.setTextNonSelectionColor方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: interactiveCompareTreeExtTreeColors
import javax.swing.tree.DefaultTreeCellRenderer; //導入方法依賴的package包/類
/**
* Custom tree colors in JTree. Compare core default renderer with Swingx
* default renderer.
*
*/
public void interactiveCompareTreeExtTreeColors() {
JTree xtree = new JTree();
Color background = Color.MAGENTA;
Color foreground = Color.YELLOW;
xtree.setBackground(background);
xtree.setForeground(foreground);
DefaultTreeCellRenderer coreTreeCellRenderer = new DefaultTreeCellRenderer();
// to get a uniform color on both tree and node
// the core default renderer needs to be configured
coreTreeCellRenderer.setBackgroundNonSelectionColor(background);
coreTreeCellRenderer.setTextNonSelectionColor(foreground);
xtree.setCellRenderer(coreTreeCellRenderer);
JTree tree = new JTree();
tree.setBackground(background);
tree.setForeground(foreground);
// swingx renderer uses tree colors
tree.setCellRenderer(xTreeRenderer);
final JXFrame frame = wrapWithScrollingInFrame(xtree, tree,
"custom tree colors - core vs. ext renderer");
frame.setVisible(true);
}
示例2: configureRenderer
import javax.swing.tree.DefaultTreeCellRenderer; //導入方法依賴的package包/類
private void configureRenderer(SynthContext context) {
TreeCellRenderer renderer = tree.getCellRenderer();
if (renderer instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)renderer;
SynthStyle style = context.getStyle();
context.setComponentState(ENABLED | SELECTED);
Color color = r.getTextSelectionColor();
if (color == null || (color instanceof UIResource)) {
r.setTextSelectionColor(style.getColor(
context, ColorType.TEXT_FOREGROUND));
}
color = r.getBackgroundSelectionColor();
if (color == null || (color instanceof UIResource)) {
r.setBackgroundSelectionColor(style.getColor(
context, ColorType.TEXT_BACKGROUND));
}
context.setComponentState(ENABLED);
color = r.getTextNonSelectionColor();
if (color == null || color instanceof UIResource) {
r.setTextNonSelectionColor(style.getColorForState(
context, ColorType.TEXT_FOREGROUND));
}
color = r.getBackgroundNonSelectionColor();
if (color == null || color instanceof UIResource) {
r.setBackgroundNonSelectionColor(style.getColorForState(
context, ColorType.TEXT_BACKGROUND));
}
}
}
示例3: applyRenderer
import javax.swing.tree.DefaultTreeCellRenderer; //導入方法依賴的package包/類
/**
* Performs configuration of the tree's renderer if the adapter's column is
* the hierarchical column, does nothing otherwise.
* <p>
*
* Note: this is legacy glue if the treeCellRenderer is of type
* DefaultTreeCellRenderer. In that case the renderer's
* background/foreground/Non/Selection colors are set to the tree's
* background/foreground depending on the adapter's selection state. Does
* nothing if the treeCellRenderer is backed by a ComponentProvider.
*
* @param component the rendering component
* @param adapter component data adapter
* @throws NullPointerException if the specified component or adapter is
* null
*/
protected Component applyRenderer(Component component,
ComponentAdapter adapter) {
if (component == null) {
throw new IllegalArgumentException("null component");
}
if (adapter == null) {
throw new IllegalArgumentException("null component data adapter");
}
if (isHierarchical(adapter.column)) {
// After all decorators have been applied, make sure that relevant
// attributes of the table cell renderer are applied to the
// tree cell renderer before the hierarchical column is rendered!
TreeCellRenderer tcr = renderer.getCellRenderer();
if (tcr instanceof JXTree.DelegatingRenderer) {
tcr = ((JXTree.DelegatingRenderer) tcr).getDelegateRenderer();
}
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// this effectively overwrites the dtcr settings
if (adapter.isSelected()) {
dtcr.setTextSelectionColor(component.getForeground());
dtcr.setBackgroundSelectionColor(component.getBackground());
} else {
dtcr.setTextNonSelectionColor(component.getForeground());
dtcr.setBackgroundNonSelectionColor(component
.getBackground());
}
}
}
return component;
}
示例4: configureRenderer
import javax.swing.tree.DefaultTreeCellRenderer; //導入方法依賴的package包/類
private void configureRenderer(SeaGlassContext context) {
TreeCellRenderer renderer = tree.getCellRenderer();
if (renderer instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer r = (DefaultTreeCellRenderer) renderer;
SeaGlassStyle style = (SeaGlassStyle)context.getStyle();
context.setComponentState(ENABLED | SELECTED);
Color color = r.getTextSelectionColor();
if (color == null || (color instanceof UIResource)) {
r.setTextSelectionColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
}
color = r.getBackgroundSelectionColor();
if (color == null || (color instanceof UIResource)) {
r.setBackgroundSelectionColor(style.getColor(context, ColorType.TEXT_BACKGROUND));
}
context.setComponentState(ENABLED);
color = r.getTextNonSelectionColor();
if (color == null || color instanceof UIResource) {
r.setTextNonSelectionColor(style.getColorForState(context, ColorType.TEXT_FOREGROUND));
}
color = r.getBackgroundNonSelectionColor();
if (color == null || color instanceof UIResource) {
r.setBackgroundNonSelectionColor(style.getColorForState(context, ColorType.TEXT_BACKGROUND));
}
}
}
示例5: getTableCellRendererComponent
import javax.swing.tree.DefaultTreeCellRenderer; //導入方法依賴的package包/類
/**
* TreeCellRenderer method. Overridden to update the visible row.
*/
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Color background;
Color foreground;
if (isSelected) {
background = table.getSelectionBackground();
foreground = table.getSelectionForeground();
} else {
background = table.getBackground();
foreground = table.getForeground();
}
highlightBorder = null;
if (realEditingRow() == row && getEditingColumn() == column) {
background = UIManager.getColor("Table.focusCellBackground");
foreground = UIManager.getColor("Table.focusCellForeground");
} else if (hasFocus) {
highlightBorder = UIManager
.getBorder("Table.focusCellHighlightBorder");
if (isCellEditable(row, column)) {
background = UIManager
.getColor("Table.focusCellBackground");
foreground = UIManager
.getColor("Table.focusCellForeground");
}
}
visibleRow = row;
setBackground(background);
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
if (isSelected) {
dtcr.setTextSelectionColor(foreground);
dtcr.setBackgroundSelectionColor(background);
} else {
dtcr.setTextNonSelectionColor(foreground);
dtcr.setBackgroundNonSelectionColor(background);
}
}
return this;
}
示例6: getTableCellRendererComponent
import javax.swing.tree.DefaultTreeCellRenderer; //導入方法依賴的package包/類
/**
* TreeCellRenderer method. Overridden to update the visible row.
*/
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Color background;
Color foreground;
if (isSelected) {
background = table.getSelectionBackground();
foreground = table.getSelectionForeground();
} else {
background = table.getBackground();
foreground = table.getForeground();
}
highlightBorder = null;
if (realEditingRow() == row && getEditingColumn() == column) {
// background = UIManager.getColor("Table.focusCellBackground");
// foreground = UIManager.getColor("Table.focusCellForeground");
} else if (hasFocus) {
if (isSelected) {
highlightBorder = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
}
else{
highlightBorder = UIManager.getBorder("Table.focusCellHighlightBorder");
}
if (isCellEditable(row, column)) {
// background = UIManager.getColor
// ("Table.focusCellBackground");
background = table.getSelectionBackground();
foreground = table.getSelectionForeground();
}
}
visibleRow = row;
setBackground(background);
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
if (isSelected) {
dtcr.setTextSelectionColor(foreground);
dtcr.setBackgroundSelectionColor(background);
} else {
dtcr.setTextNonSelectionColor(foreground);
dtcr.setBackgroundNonSelectionColor(background);
}
}
return this;
}