package _13;
import java.util.Hashtable;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
public class HashConstructTree extends JFrame {
public HashConstructTree() {
String[] s1 = {"A", "B", "C"};
String[] s2 = {"a", "b", "c"};
Hashtable<String, String[]> hashtable = new Hashtable<>();
hashtable.put("大写字母", s1);
hashtable.put("小写字母", s2);
JTree tree = new JTree(hashtable);
// 滚动面板相关代码
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(tree); // 将树形组件放入滚动面板的视口
add(scrollPane); // 将滚动面板添加到窗口
}
public static void main(String[] args) {
HashConstructTree frame = new HashConstructTree();
frame.setTitle("HashConstructTree");
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
1048

被折叠的 条评论
为什么被折叠?



