import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Temp {
public Temp() {
JFrame J = new JFrame("MENU");
Container C = J.getContentPane();//要用J来获取,就像树一样
String[] s1 = { "11", "22", "33" };
String[] s2 = { "$$", "55", "99" };
String[] s3 = { "55", "ii", "pp" };
Hashtable H1 = new Hashtable();
Hashtable H2 = new Hashtable();
H1.put("Menu1", s1);
H1.put("Menu2", s2);
H2.put("Menu3-1", s3);
H1.put("Menu3", H2);
JTree tree = new JTree(H1);
JScrollPane scrollpane = new JScrollPane();
scrollpane.setViewportView(tree);//setVisible 为布尔值,在这不能用
C.add(scrollpane);
J.pack();
J.setVisible(true);
J.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public static void main(String args[]) {
new Temp();
}
}