本文整理了Java中javax.swing.JTree.getBackground()
方法的一些代码示例,展示了JTree.getBackground()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTree.getBackground()
方法的具体详情如下:
包路径:javax.swing.JTree
类名称:JTree
方法名:getBackground
暂无
代码示例来源:origin: stackoverflow.com
private class Renderer extends DefaultTreeCellRenderer{
public Renderer() {
setOpaque(true);
}
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded, boolean leaf, int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
setBackground(selected ? Color.LIGHT_GRAY :
(leaf ? Color.GRAY : tree.getBackground()));
return this;
}
}
代码示例来源:origin: org.appdapter/org.appdapter.lib.gui
@Override public Component getTreeCellRendererComponent(JTree table, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
return renderComponent(table, value, row, -1, selected, -1, table.getForeground(), table.getBackground());
}
}
代码示例来源:origin: stackoverflow.com
tree.setCellRenderer(new DefaultTreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) {
JComponent c = (JComponent) super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
//setBackgroundSelectionColor(Color.BLUE);
c.setBackground(selected ? Color.BLUE : tree.getBackground());
c.setOpaque(true);
return c;
}
});
代码示例来源:origin: stackoverflow.com
IconValue iconValue = new IconValue() {
@Override
public Icon getIcon(Object value) {
return UIManager.getIcon("FileView.directoryIcon");
}
};
DefaultTreeRenderer treeCellRenderer = new DefaultTreeRenderer(iconValue) {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
if (selected && leaf) {
c.setBackground(Color.RED);
} else {
setBackground(tree.getBackground());
}
return c;
}
};
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-beans
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value,
sel, expanded, leaf, row, hasFocus);
if (!sel) {
setBackgroundNonSelectionColor(tree.getBackground());
}
if (value instanceof JavaElement) {
JavaElement javaElement = (JavaElement) value;
label.setIcon(javaElement.getIcon());
label.setToolTipText(javaElement.getTooltip());
label.setEnabled( !javaElement.isDisabled() );
}
return label;
}
}
代码示例来源:origin: org.apache.river.examples/browser
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean isSelected,
boolean isExpanded,
boolean isLeaf,
int row,
boolean cellHasFocus){
//label.setFont(tree.getFont());
label.setForeground(tree.getForeground());
if(isSelected){
//label.setBackground(UIManager.getColor("Tree.backgroundSelectionColor"));
//label.setForeground(UIManager.getColor("Tree.textSelectionColor"));
label.setBackground(MetalLookAndFeel.getPrimaryControl());
} else {
//label.setBackground(UIManager.getColor("Tree.backgroundNonSelectionColor"));
//label.setForeground(UIManager.getColor("Tree.textNonSelectionColor"));
label.setBackground(tree.getBackground());
}
ObjectNode node = (ObjectNode) value;
label.setText(node.getTitle());
label.setIcon(node.getIcon());
return label;
}
}
代码示例来源:origin: jcbvm/i18n-editor
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
TranslationTreeNode node = (TranslationTreeNode) value;
TranslationTreeModel model = (TranslationTreeModel) tree.getModel();
JLabel l = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
l.setOpaque(true);
l.setForeground(tree.getForeground());
l.setBackground(tree.getBackground());
if (!node.isRoot() && (node.hasError() || model.hasErrorChildNode(node))) {
l.setIcon(new TranslationTreeStatusIcon(StatusIconType.Warning));
}
if (node.isRoot()) {
l.setIcon(ROOT_ICON);
}
if (selected) {
l.setBackground(selectionBackground);
}
return l;
}
}
代码示例来源:origin: protegeproject/protege
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
setFocusedEntity(entity);
JComponent c = (JComponent) super.getTreeCellRendererComponent(tree,
node.getUserObject(),
sel,
expanded,
leaf,
row,
hasFocus);
if (node.getUserObject() instanceof OWLAxiom) {
if (node.getParent().getIndex(node) == node.getParent().getChildCount() - 1) {
c.setBorder(BorderFactory.createMatteBorder(1, 20, 20, 0, tree.getBackground()));
}
else {
c.setBorder(BorderFactory.createMatteBorder(1, 20, 0, 0, tree.getBackground()));
}
}
else {
c.setBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0));
}
setHighlightKeywords(true);
return c;
}
}
代码示例来源:origin: edu.stanford.protege/org.protege.editor.owl
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
setFocusedEntity(entity);
JComponent c = (JComponent) super.getTreeCellRendererComponent(tree,
node.getUserObject(),
sel,
expanded,
leaf,
row,
hasFocus);
if (node.getUserObject() instanceof OWLAxiom) {
if (node.getParent().getIndex(node) == node.getParent().getChildCount() - 1) {
c.setBorder(BorderFactory.createMatteBorder(1, 20, 20, 0, tree.getBackground()));
}
else {
c.setBorder(BorderFactory.createMatteBorder(1, 20, 0, 0, tree.getBackground()));
}
}
else {
c.setBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0));
}
setHighlightKeywords(true);
return c;
}
}
代码示例来源:origin: edu.stanford.protege/protege-editor-owl
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
setFocusedEntity(entity);
JComponent c = (JComponent) super.getTreeCellRendererComponent(tree,
node.getUserObject(),
sel,
expanded,
leaf,
row,
hasFocus);
if (node.getUserObject() instanceof OWLAxiom) {
if (node.getParent().getIndex(node) == node.getParent().getChildCount() - 1) {
c.setBorder(BorderFactory.createMatteBorder(1, 20, 20, 0, tree.getBackground()));
}
else {
c.setBorder(BorderFactory.createMatteBorder(1, 20, 0, 0, tree.getBackground()));
}
}
else {
c.setBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0));
}
setHighlightKeywords(true);
return c;
}
}
代码示例来源:origin: org.protege/protege-editor-owl
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
setFocusedEntity(entity);
JComponent c = (JComponent) super.getTreeCellRendererComponent(tree,
node.getUserObject(),
sel,
expanded,
leaf,
row,
hasFocus);
if (node.getUserObject() instanceof OWLAxiom) {
if (node.getParent().getIndex(node) == node.getParent().getChildCount() - 1) {
c.setBorder(BorderFactory.createMatteBorder(1, 20, 20, 0, tree.getBackground()));
}
else {
c.setBorder(BorderFactory.createMatteBorder(1, 20, 0, 0, tree.getBackground()));
}
}
else {
c.setBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0));
}
setHighlightKeywords(true);
return c;
}
}
代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui
public Component getTreeCellRendererComponent(final JTree _tree, final Object _value, final boolean _selected,
final boolean _expanded, final boolean _leaf, final int _row, final boolean _hasFocus) {
if (treeSelectionForeground_ == null) {
treeSelectionForeground_ = UIManager.getColor("Tree.selectionForeground");
}
if (treeSelectionBackground_ == null) {
treeSelectionBackground_ = UIManager.getColor("Tree.selectionBackground");
}
if (_selected) {
setBackground(treeSelectionBackground_);
setForeground(treeSelectionForeground_);
} else {
setBackground(_tree.getBackground());
setForeground(_tree.getForeground());
}
setValue(_value);
return this;
}
代码示例来源:origin: RPTools/maptool
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row,
boolean hasFocus) {
node = (DefaultMutableTreeNode) value;
mtnode = (MaptoolNode) node.getUserObject();
setText(mtnode.toString());
setBackground(tree.getBackground());
setEnabled(tree.isEnabled());
setComponentOrientation(tree.getComponentOrientation());
return this;
}
代码示例来源:origin: UNIVALI-LITE/Portugol-Studio
@Override
public void paint(Graphics g, JComponent c) {
JTree tree = (JTree) c;
if(tree.isOpaque()){
g.setColor(tree.getBackground());
g.fillRect(0, 0, tree.getWidth(), tree.getHeight());
}
if (tree.getSelectionCount() > 0) {
g.setColor(ColorController.COR_DESTAQUE);
//@see http://ateraimemo.com/Swing/TreeRowSelection.html
for (int i : tree.getSelectionRows()) {
Rectangle r = tree.getRowBounds(i);
g.fillRect(0, r.y, tree.getWidth(), r.height);
}
}
super.paint(g, c);
if (tree.getLeadSelectionPath() != null) {
Rectangle r = tree.getRowBounds(getRowForPath(tree, tree.getLeadSelectionPath()));
g.setColor(tree.hasFocus() ? ColorController.FUNDO_MEDIO.brighter(): ColorController.FUNDO_MEDIO);
// g.drawRect(0, r.y, tree.getWidth() - 1, r.height - 1);
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-localhistory
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if(!(value instanceof FileNode)) {
return this;
}
FileNode node = (FileNode) value;
stringDisplayer = renderer.getTreeCellRendererComponent(tree,
node.getText(), isSelected, expanded, leaf, row, hasFocus);
if(!(value instanceof StoreEntryNode)) {
// renderer.setIcon (null);
}
stringDisplayer.setEnabled(value instanceof StoreEntryNode);
//HtmlRenderer does not tolerate null colors - real ones are needed to
//ensure fg/bg always diverge enough to be readable
if (stringDisplayer.getBackground() == null) {
stringDisplayer.setBackground (tree.getBackground());
}
if (stringDisplayer.getForeground() == null) {
stringDisplayer.setForeground (tree.getForeground());
}
if (check != null) {
check.setSelected(node.isSelected());
}
return this;
}
代码示例来源:origin: jpcsp/jpcsp
/** Configures a tree cell renderer and sets up sizing and the
* backing image from it */
public boolean configure (Object nd, JScrollPane tv, JTree tree, TreePath path, int row) {
setLastRendereredObject(nd);
setLastRenderedScrollPane (tv);
Component renderer = null;
bg = tree.getBackground();
boolean sel = tree.isSelectionEmpty() ? false :
tree.getSelectionModel().isPathSelected(path);
boolean exp = tree.isExpanded(path);
boolean leaf = !exp && tree.getModel().isLeaf(nd);
boolean lead = path.equals(tree.getSelectionModel().getLeadSelectionPath());
renderer = tree.getCellRenderer().getTreeCellRendererComponent(tree, nd, sel, exp, leaf, row, lead);
if (renderer != null) {
setComponent (renderer);
}
return true;
}
代码示例来源:origin: org.netbeans.api/org-openide-explorer
/** Configures a tree cell renderer and sets up sizing and the
* backing image from it */
public boolean configure (Object nd, JScrollPane tv, JTree tree, TreePath path, int row) {
boolean sameVn = setLastRendereredObject(nd);
boolean sameComp = setLastRenderedScrollPane (tv);
Component renderer = null;
bg = tree.getBackground();
boolean sel = tree.isSelectionEmpty() ? false :
tree.getSelectionModel().isPathSelected(path);
boolean exp = tree.isExpanded(path);
boolean leaf = !exp && tree.getModel().isLeaf(nd);
boolean lead = path.equals(tree.getSelectionModel().getLeadSelectionPath());
renderer = tree.getCellRenderer().getTreeCellRendererComponent(tree, nd, sel, exp, leaf, row, lead);
if (renderer != null) {
setComponent (renderer);
}
return true;
}
代码示例来源:origin: it.tidalwave.netbeans/it-tidalwave-netbeans-explorer
/*******************************************************************************
*
*
******************************************************************************/
private void patchRenderer()
{
if (Boolean.getBoolean("nb.useSwingHtmlRendering") && !rendererPatched)
{
rendererPatched = true;
final OldPatchedNodeRenderer nodeRenderer = new OldPatchedNodeRenderer(tree.getCellRenderer());
nodeRenderer.setBackgroundSelectionColor(getColorProperty("Tree.selectionBackground"));
nodeRenderer.setBackgroundNonSelectionColor(tree.getBackground());
nodeRenderer.setTextSelectionColor(getColorProperty("Tree.selectionForeground"));
nodeRenderer.setTextNonSelectionColor(tree.getForeground());
tree.setCellRenderer(nodeRenderer);
}
}
代码示例来源:origin: org.fudaa.framework.ebli/ebli-2d
public Component getTreeCellRendererComponent(final JTree _tree, final Object _value, final boolean _selected,
final boolean _expanded, final boolean _leaf, final int _row, final boolean _hasFocus) {
this.setFont(_tree.getFont());
setIcon(((LayerNode) _value).getIcon());
setText(_value.toString());
final boolean selectable = isSelectable(_value, _leaf);
if (_selected && selectable) {
setBackground(selectedBackground_);
setForeground(selectedForground_);
} else {
setBackground(_tree.getBackground());
setForeground(_tree.getForeground());
}
if (selectable) {
setToolTipText(getText());
} else {
setToolTipText(getText() + ": " + CtuluLib.getS("Non slectionnable"));
}
setBorder((selectable && _hasFocus) ? focusBorderColor_ : CtuluCellRenderer.BORDER_NO_FOCUS);
setEnabled(_tree.isEnabled());
return this;
}
}
代码示例来源:origin: org.fudaa.framework.ebli/ebli-2d
public Component getTreeCellRendererComponent(final JTree _tree, final Object _value, final boolean _selected,
final boolean _expanded, final boolean _leaf, final int _row, final boolean _hasFocus) {
this.setFont(_tree.getFont());
setIcon(((LayerNode) _value).getIcon());
setText(_value.toString());
final boolean selectable = isSelectable(_value, _leaf);
if (_selected && selectable) {
setBackground(selectedBackground_);
setForeground(selectedForground_);
} else {
setBackground(_tree.getBackground());
setForeground(_tree.getForeground());
}
if (selectable) {
setToolTipText(getText());
} else {
setToolTipText(getText() + ": " + CtuluLib.getS("Non slectionnable"));
}
setBorder((selectable && _hasFocus) ? focusBorderColor_ : CtuluCellRenderer.BORDER_NO_FOCUS);
setEnabled(_tree.isEnabled());
return this;
}
}
内容来源于网络,如有侵权,请联系作者删除!