當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultTreeCellRenderer.setTextNonSelectionColor方法代碼示例

本文整理匯總了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);
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:27,代碼來源:TreeRendererTest.java

示例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));
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:33,代碼來源:SynthTreeUI.java

示例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;
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:51,代碼來源:JXTreeTable.java

示例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));
        }
    }
}
 
開發者ID:khuxtable,項目名稱:seaglass,代碼行數:29,代碼來源:SeaGlassTreeUI.java

示例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;
}
 
開發者ID:dvorka,項目名稱:mindraider,代碼行數:48,代碼來源:JTreeTable.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-taverna-workbench,代碼行數:52,代碼來源:JTreeTable.java


注:本文中的javax.swing.tree.DefaultTreeCellRenderer.setTextNonSelectionColor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。