📄 treestringcomparator.java
字号:
// TreeStringComparator.java// This class compares the contents of the userObject as strings.// It's case-insensitive.//package jswing.ch17; import java.util.*;import javax.swing.tree.DefaultMutableTreeNode;public class TreeStringComparator implements Comparator { public int compare(Object o1, Object o2) { if (!(o1 instanceof DefaultMutableTreeNode && o2 instanceof DefaultMutableTreeNode)) { throw new IllegalArgumentException("Can only compare DefaultMutableTreeNode objects"); } String s1 = ((DefaultMutableTreeNode)o1).getUserObject().toString(); String s2 = ((DefaultMutableTreeNode)o2).getUserObject().toString(); return s1.compareToIgnoreCase(s2); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -