本文实例讲述了 ayunan 中 pohon 与滚动条用法。分享给大家供大家参考。具体如下 :
impor java.awt.*; import java.awt.event.*; impor javax.swing.*; import javax.swing.tree.*; tes kelas publik memperluas japplet {pohon jtree; JTextfield JTF; public void init () {container contentPane = getContentPane (); contentpane.setLayout (borderlayout () baru ()); DefaultMutableTreeNode TOP = DefaultMutableTreeNode baru ("Opsi"); DefaultMutableTreeNode a = New DefaultMutableTreeNode ("A"); top.add (a); DefaultMutableTreenode a1 = DefaultMutableTreeNode baru ("A1"); A.Add (A1); DefaultMutableTreenode a2 = DefaultMutableTreeNode baru ("A2"); A.Add (A2); DefaultMutableTreenode b = DefaultMutableTreenode baru ("b"); top.add (b); DefaultMutableTreenode b1 = New DefaultMutableTreeNode ("B1"); B.Add (B1); DefaultMutableTreenode b2 = DefaultMutableTreeNode baru ("b2"); B.Add (B2); pohon = Jtree baru (atas); int v = scrollpaneconstants.vertical_scrollbar_as_needed; int h = scrollpaneconstants.horizontal_scrollbar_as_needed; Jscrollpane jsp = jscrollpane baru (pohon, v, h); contentpane.add (JSP, borderlayout.center); JTF = JTextField baru ("", 20); contentpane.add (jtf, borderlayout.south); Tree.addmouseListener (mouseadapter baru () {public void mouseclicked (mouseEvent me) {domouseClicked (me);}}); } void domouseClicked (mouseEvent me) {treepath tp = tree.getPathForlocation (me.getx (), me.gety ()); if (tp! = null) jtf.setText (tp.toString ()); selain itu jtf.setText (""); }}
希望本文所述对大家的 Java 程序设计有所帮助。