📄 urlnoderenderer.java
字号:
/* * UrlNodeRenderer.java * * Created on September 20, 2004, 11:14 AM */import javax.swing.*;import javax.swing.tree.*;import java.awt.*;import java.net.*;/** * Custom tree node renderer. If the url has a match, it will be drawn in blue * simple icons are used for all nodes. * * @author Mark Pendergast */public class UrlNodeRenderer extends DefaultTreeCellRenderer{ /** * icon used to display on the search tree */ public static Icon icon= null; /** Creates a new instance of UrlNodeRenderer */ public UrlNodeRenderer() { icon = new ImageIcon(getClass().getResource("SPIDERWEB.gif")); } /** * Sets the value of the current tree cell to value. * If selected is true, the cell will be drawn as if selected. * If expanded is true the node is currently expanded and if leaf is * true the node represets a leaf and if hasFocus is true the node * currently has focus. tree is the JTree the receiver is being * configured for. Returns the Component that the renderer uses to draw the value. * * Modified the TreeCellRender to match a specific nodes attributes. If * the node is a match, then blue is used for the text color. Icon is customized * * @param tree the JTree being redrawn * @param value node in the tree * @param sel true if selected by the user * @param expanded true if path is expanded * @param leaf true if this node is a leaf * @param row row number (vertical position) * @param hasFocus true if it has the focus * @return the Component that the renderer uses to draw the value */ public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasFocus); UrlTreeNode node = (UrlTreeNode)(((DefaultMutableTreeNode)value).getUserObject()); if (node.isMatch()) // set color setForeground(Color.blue); else setForeground(Color.black); if(icon != null) // set a custom icon { setOpenIcon(icon); setClosedIcon(icon); setLeafIcon(icon); } return this; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -