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


Java DefaultTreeCellRenderer.setBackgroundNonSelectionColor方法代碼示例

本文整理匯總了Java中javax.swing.tree.DefaultTreeCellRenderer.setBackgroundNonSelectionColor方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultTreeCellRenderer.setBackgroundNonSelectionColor方法的具體用法?Java DefaultTreeCellRenderer.setBackgroundNonSelectionColor怎麽用?Java DefaultTreeCellRenderer.setBackgroundNonSelectionColor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.tree.DefaultTreeCellRenderer的用法示例。


在下文中一共展示了DefaultTreeCellRenderer.setBackgroundNonSelectionColor方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: interactiveCoreRendererCustomColor

import javax.swing.tree.DefaultTreeCellRenderer; //導入方法依賴的package包/類
/**
 * Custom renderer colors of core DefaultTreeCellRenderer not respected.
 * This is intentional: treeTable's highlighters must rule, so the
 * renderer colors are used to force the treecellrenderer to use the 
 * correct values.
 */
public void interactiveCoreRendererCustomColor() {
    JXTreeTable treeTable = new JXTreeTable(new FileSystemModel());
    treeTable.addHighlighter(HighlighterFactory.createSimpleStriping());
    DefaultTreeCellRenderer legacy = createBackgroundTreeRenderer();
    // in a treetable this has no effect: treetable.applyRenderer 
    // internally resets them to the same colors as tree itself
    // (configured by the table's highlighters
    legacy.setBackgroundNonSelectionColor(Color.YELLOW);
    legacy.setBackgroundSelectionColor(Color.RED);
    treeTable.setTreeCellRenderer(legacy);
    JTree tree = new JXTree(treeTable.getTreeTableModel());
    DefaultTreeCellRenderer other = createBackgroundTreeRenderer();
    other.setBackgroundNonSelectionColor(Color.YELLOW);
    other.setBackgroundSelectionColor(Color.RED);
    tree.setCellRenderer(other);
    JXFrame frame = wrapWithScrollingInFrame(treeTable, tree, "legacy renderers - highlight complete cell");
    frame.setVisible(true);  
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:25,代碼來源:JXTreeTableIssues.java

示例2: 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

示例3: 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

示例4: 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

示例5: initGUI

import javax.swing.tree.DefaultTreeCellRenderer; //導入方法依賴的package包/類
public void initGUI() {
controlPanelTitle = "SOCR 3D Charts & Graphs";
implementedFile = "implementedCharts3D.txt";

clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

// comment or uncomment to activate the buttons.
addButton2(ABOUT, "Find Details about this Type of Chart", this);
addButton2(HELP, "Help with This type of Chart", this);
addButton2(SEARCH, "Searc for the right type of Chart", this);
addButton(SNAPSHOT, "Save a Snapshot/Image of this SOCRChart Applet", this);
addButton(COPY, "Copy data from table to mouse buffer", this);
addButton(PASTE, "Paste in Data", this);
addButton(FILE, "Open File", this);
// end buttons.
north.add(Box.createVerticalStrut(8));
      packControlPane();
      
   tree = new ChartTree_dynamic(implementedFile, codeBase).getTree();
   tree.addTreeSelectionListener(this);
	
Color bg = fControlPanel.getBackground();
DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer();
      treeRenderer.setBackgroundNonSelectionColor(bg);
      //treeRenderer.setBackgroundSelectionColor(Color.white);
      tree.setCellRenderer(treeRenderer);
tree.setOpaque(true);
tree.setBackground(bg);

//tree.setScrollsOnExpand(true);
north.add(tree);
north.add(Box.createVerticalStrut(8));	

// the reset initGUI
super.initGUI();
getParameterFromHtml();
  }
 
開發者ID:SOCR,項目名稱:HTML5_WebSite,代碼行數:38,代碼來源:SOCRChart3D.java

示例6: 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

示例7: createDocPane

import javax.swing.tree.DefaultTreeCellRenderer; //導入方法依賴的package包/類
private JTree createDocPane() {
    final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    for (Map.Entry<?,? extends List<?>> docEntry : getDoc().getItemTree()
        .entrySet()) {
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(docEntry.getKey());
        root.add(node);
        for (Object rule : docEntry.getValue()) {
            node.add(new DefaultMutableTreeNode(rule));
        }
    }
    final JTree result = new JTree(root) {
        @Override
        public String getToolTipText(MouseEvent evt) {
            if (getRowForLocation(evt.getX(), evt.getY()) == -1) {
                return null;
            }
            TreePath curPath = getPathForLocation(evt.getX(), evt.getY());
            Object userObject =
                ((DefaultMutableTreeNode) curPath.getLastPathComponent()).getUserObject();
            return getToolTip(userObject);
        }
    };
    result.setRootVisible(false);
    result.setShowsRootHandles(true);
    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) result.getCellRenderer();
    renderer.setBackgroundNonSelectionColor(null);
    renderer.setBackgroundSelectionColor(null);
    renderer.setTextSelectionColor(null);
    renderer.setLeafIcon(null);
    renderer.setClosedIcon(null);
    renderer.setOpenIcon(null);
    result.setCellRenderer(renderer);
    ToolTipManager.sharedInstance()
        .registerComponent(result);
    result.addMouseListener(new DismissDelayer(result));
    for (int i = 0; i < root.getChildCount(); i++) {
        result
            .expandPath(new TreePath(((DefaultMutableTreeNode) root.getChildAt(i)).getPath()));
    }
    result.setBackground(null);
    return result;
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:43,代碼來源:ControlDisplay.java

示例8: OptionGroupUI

import javax.swing.tree.DefaultTreeCellRenderer; //導入方法依賴的package包/類
/**
 * The constructor that will add the items to this panel.
 *
 * @param gui The enclosing {@code GUI}.
 * @param group The {@code OptionGroup} encapsulate.
 * @param editable Is the group editable.
 */
public OptionGroupUI(GUI gui, OptionGroup group, boolean editable) {
    super("ReportPanelUI");

    this.gui = gui;
    this.group = group;
    this.editable = editable;

    setLayout(new MigLayout("fill", "[200:]unrelated[550:, grow, fill]",
                            "[top]"));

    DefaultMutableTreeNode root = new DefaultMutableTreeNode(group);
    buildTree(group, root);

    DefaultTreeModel treeModel = new DefaultTreeModel(root);
    tree = new JTree(treeModel) {
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(200, super.getPreferredSize().height);
            }
            @Override
            public String convertValueToText(Object value,
                boolean selected, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
                DefaultMutableTreeNode node
                    = (DefaultMutableTreeNode)value;
                Option option = (Option)node.getUserObject();
                return Messages.getName(option.getId());
            }
        };

    tree.setOpaque(false);
    tree.addTreeSelectionListener(this);
    DefaultTreeCellRenderer renderer
        = (DefaultTreeCellRenderer)tree.getCellRenderer();
    renderer.setBackgroundNonSelectionColor(new Color(0, 0, 0, 1));

    add(tree);
    detailPanel = new MigPanel();
    detailPanel.setLayout(new MigLayout("wrap 2", "[fill]related[fill]"));
    detailPanel.setOpaque(false);
    add(detailPanel, "grow");
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:50,代碼來源:OptionGroupUI.java

示例9: 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

示例10: initGUI

import javax.swing.tree.DefaultTreeCellRenderer; //導入方法依賴的package包/類
public void initGUI() {
	controlPanelTitle = "SOCR Applications/";
	implementedFile = "implementedApplications.txt";

	clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

	// comment or uncomment to activate the buttons.
	addButton2(ABOUT, "Find Details about this Type of Application", this);
	addButton2(HELP, "Help with This type of Application", this);
	addButton2(SEARCH, "Searc for the right type of application", this);
	addButton(SNAPSHOT, "Save a Snapshot/Image of this SOCRApplication Applet", this);
	addButton(COPY, "Copy data from table to mouse buffer", this);
	
//	addRadioButton("Switch Input Matrix:", "Switch Input Matrix", formatArray, 0, this);
	/*show_tangent = new JCheckBox();
	addJLabel(new JLabel("Show"));
	addJCheckBox(show_tangent);*/
	
	//System.out.println("SOCRApplications initGUI get called");
//	addRadioButton("Number of Stocks:", "", numStocksArray, 0, this);		
//	addRadioButton2("Show Tangent Line :", "", on_off, 0, this);
	
//	addButton(PASTE, "Paste in Data", this);
	addButton(FILE, "Open File", this);
	// end buttons.
	north.add(Box.createVerticalStrut(8));
       packControlPane();

	/*try{
			tree = new ChartTree().getTree();
		}  catch (Exception e1) {
		         JOptionPane.showMessageDialog(this, e1.getMessage());
		        e1.printStackTrace();
		}*/
       
    tree = new ChartTree_dynamic(implementedFile, codeBase, "SOCRApplications").getTree();
    tree.addTreeSelectionListener(this);
		
	Color bg = fControlPanel.getBackground();
	DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer();
       treeRenderer.setBackgroundNonSelectionColor(bg);
       //treeRenderer.setBackgroundSelectionColor(Color.white);
       tree.setCellRenderer(treeRenderer);
	tree.setOpaque(true);
	tree.setBackground(bg);

	//tree.setScrollsOnExpand(true);
	north.add(tree);
	north.add(Box.createVerticalStrut(8));	

	// the reset initGUI
	super.initGUI();
   }
 
開發者ID:SOCR,項目名稱:HTML5_WebSite,代碼行數:54,代碼來源:SOCRApplications.java

示例11: initGUI

import javax.swing.tree.DefaultTreeCellRenderer; //導入方法依賴的package包/類
public void initGUI() {
controlPanelTitle = "SOCR Charts & Graphs";
implementedFile = "implementedCharts.txt";

try {
	clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
} catch (Exception e) {
	System.out.println("SOCRChart:initGUI(): No Security Access!");
}

// comment or uncomment to activate the buttons.
addButton2(ABOUT, "Find Details about this Type of Chart", this);
addButton2(HELP, "Help with This type of Chart", this);
addButton2(SEARCH, "Searc for the right type of Chart", this);
addButton(SNAPSHOT, "Save a Snapshot/Image of this SOCRChart Applet", this);
addButton(COPY, "Copy data from table to mouse buffer", this);
addButton(PASTE, "Paste in Data", this);
addButton(FILE, "Open File", this);
// end buttons.
north.add(Box.createVerticalStrut(8));
      packControlPane();
      
   tree = new ChartTree_dynamic(implementedFile, codeBase).getTree();
   tree.addTreeSelectionListener(this);
	
Color bg = fControlPanel.getBackground();
DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer();
      treeRenderer.setBackgroundNonSelectionColor(bg);
      //treeRenderer.setBackgroundSelectionColor(Color.white);
      tree.setCellRenderer(treeRenderer);
tree.setOpaque(true);
tree.setBackground(bg);

//tree.setScrollsOnExpand(true);
north.add(tree);
north.add(Box.createVerticalStrut(8));	

// the reset initGUI
super.initGUI();
getParameterFromHtml();
  }
 
開發者ID:SOCR,項目名稱:HTML5_WebSite,代碼行數:42,代碼來源:SOCRChart.java

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