本文整理汇总了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);
}
示例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);
}
示例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));
}
}
}
示例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;
}
示例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();
}
示例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));
}
}
}
示例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;
}
示例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");
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}