本文整理汇总了Java中javax.swing.tree.DefaultTreeCellRenderer.setTextSelectionColor方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultTreeCellRenderer.setTextSelectionColor方法的具体用法?Java DefaultTreeCellRenderer.setTextSelectionColor怎么用?Java DefaultTreeCellRenderer.setTextSelectionColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.DefaultTreeCellRenderer
的用法示例。
在下文中一共展示了DefaultTreeCellRenderer.setTextSelectionColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入方法依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
@Override
public void updateUI ()
{
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
}
}
示例2: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入方法依赖的package包/类
/**
* UpdateUI is overridden to set the colors of the Tree's renderer
* to match that of the table.
*/
@Override
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
final TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
final DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tcr;
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// renderer.setBorderSelectionColor(null);
renderer.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
renderer.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
}
}
示例3: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入方法依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager
.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager
.getColor("Table.selectionBackground"));
((DefaultTreeCellRenderer)this.getCellRenderer()).setLeafIcon(null);
((DefaultTreeCellRenderer)this.getCellRenderer()).setOpenIcon(null);
((DefaultTreeCellRenderer)this.getCellRenderer()).setClosedIcon(null);
}
}
示例4: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入方法依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager
.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager
.getColor("Table.selectionBackground"));
}
}
示例5: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入方法依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
@Override
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
((DefaultTreeCellRenderer) this.getCellRenderer()).setLeafIcon(null);
((DefaultTreeCellRenderer) this.getCellRenderer()).setOpenIcon(null);
((DefaultTreeCellRenderer) this.getCellRenderer()).setClosedIcon(null);
}
}
示例6: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入方法依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
@Override
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager.getColor("Table.selectionBackground"));
}
}
示例7: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入方法依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer
* to match that of the table.
*/
@Override
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
// TODO JW: need to revisit...
// a) the "real" of a JXTree is always wrapped into a DelegatingRenderer
// consequently the if-block never executes
// b) even if it does it probably (?) should not
// unconditionally overwrite custom selection colors.
// Check for UIResources instead.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is null.
dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(
UIManager.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(
UIManager.getColor("Table.selectionBackground"));
}
}
示例8: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入方法依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer to
* match that of the table.
*/
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager
.getColor("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager
.getColor("Table.selectionBackground"));
}
}
示例9: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入方法依赖的package包/类
/**
* updateUI is overridden to set the colors of the Tree's renderer
* to match that of the table.
*/
public void updateUI() {
super.updateUI();
// Make the tree's cell renderer use the table's cell selection
// colors.
TreeCellRenderer tcr = getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer)tcr);
// For 1.1 uncomment this, 1.2 has a bug that will cause an
// exception to be thrown if the border selection color is
// null.
// dtcr.setBorderSelectionColor(null);
dtcr.setTextSelectionColor(UIManager.getColor
("Table.selectionForeground"));
dtcr.setBackgroundSelectionColor(UIManager.getColor
("Table.selectionBackground"));
}
}
示例10: 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));
}
}
}
示例11: updateUI
import javax.swing.tree.DefaultTreeCellRenderer; //导入方法依赖的package包/类
public void updateUI() {
super.updateUI();
TreeCellRenderer tcr = super.getCellRenderer();
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = (DefaultTreeCellRenderer)tcr;
dtcr.setTextSelectionColor(UIUtil.getTableSelectionForeground());
dtcr.setBackgroundSelectionColor(UIUtil.getTableSelectionBackground());
}
}
示例12: 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;
}
示例13: 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));
}
}
}
示例14: 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;
}
示例15: DecoratedTreeDemo
import javax.swing.tree.DefaultTreeCellRenderer; //导入方法依赖的package包/类
public DecoratedTreeDemo() {
super("DecoratedTree");
getRootPane().putClientProperty(KEY_DESCRIPTION, "The DecoratedTreeUI adds clickable decorations on the right side of a JTree. This is a handy way to provide shortcuts to functions, but because these are \"stamped\" components: they don't really exist in the tree hierarchy. Because of this they are not keyboard accessible, and therefore you need redundant ways to access these features for special needs users (probably keyboard shortcuts).");
closeable = new DefaultMutableTreeNode("Deletable");
playable = new DefaultMutableTreeNode("Playable");
warning = new DefaultMutableTreeNode("Warning");
rateable = new DefaultMutableTreeNode("Rateable");
tree.putClientProperty( DecoratedTreeUI.KEY_DECORATIONS, new TreeDecoration[] { progressDecoration,
starDecoration1, starDecoration2, starDecoration3, starDecoration4, starDecoration5,
closeDecoration, playPauseDecoration, warningDecoration, refreshDecoration });
tree.setUI(new DecoratedTreeUI());
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setBackgroundSelectionColor( SystemColor.textHighlight );
renderer.setTextSelectionColor( SystemColor.textHighlightText );
/** We want to call setCellRenderer(..) *after* setUI(..) in this demo app
* just to verify that they can work in this order...
*/
tree.setCellRenderer(renderer);
//give the aqua progress indicator just a little bit more vertical space
tree.setRowHeight(24);
loadChildNodes();
tree.setPreferredSize(new Dimension(200, 150));
getContentPane().setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
getContentPane().add(tree, c);
c.weighty = 0; c.gridy++;
getContentPane().add(stretchHighlight, c);
stretchHighlight.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tree.setUI(new DecoratedTreeUI(stretchHighlight.isSelected()));
}
});
stretchHighlight.setBackground(tree.getBackground());
stretchHighlight.setOpaque(true);
}