swing中Tree与滚动条用法实例分析
程序员文章站
2024-03-05 17:44:01
本文实例讲述了swing中tree与滚动条用法。分享给大家供大家参考。具体如下:
import java.awt.*;
import java.awt.even...
本文实例讲述了swing中tree与滚动条用法。分享给大家供大家参考。具体如下:
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.tree.*; public class test extends japplet{ jtree tree; jtextfield jtf; public void init(){ container contentpane = getcontentpane(); contentpane.setlayout(new borderlayout()); defaultmutabletreenode top = new defaultmutabletreenode("options"); defaultmutabletreenode a = new defaultmutabletreenode("a"); top.add(a); defaultmutabletreenode a1 = new defaultmutabletreenode("a1"); a.add(a1); defaultmutabletreenode a2 = new defaultmutabletreenode("a2"); a.add(a2); defaultmutabletreenode b = new defaultmutabletreenode("b"); top.add(b); defaultmutabletreenode b1 = new defaultmutabletreenode("b1"); b.add(b1); defaultmutabletreenode b2 = new defaultmutabletreenode("b2"); b.add(b2); tree = new jtree(top); int v = scrollpaneconstants.vertical_scrollbar_as_needed; int h = scrollpaneconstants.horizontal_scrollbar_as_needed; jscrollpane jsp = new jscrollpane(tree,v,h); contentpane.add(jsp, borderlayout.center); jtf = new jtextfield("", 20); contentpane.add(jtf, borderlayout.south); tree.addmouselistener(new mouseadapter(){ 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()); else jtf.settext(""); } }
希望本文所述对大家的java程序设计有所帮助。
推荐阅读
-
PHP中auto_prepend_file与auto_append_file用法实例分析,autoprependfile
-
Android中AsyncTask与handler用法实例分析
-
Android中AsyncTask与handler用法实例分析
-
Java中的匿名对象定义与用法实例分析
-
Mysql数据库中数据表的优化、外键与三范式用法实例分析
-
python中lambda与def用法对比实例分析
-
js中apply()和call()的区别与用法实例分析
-
PHP中auto_prepend_file与auto_append_file用法实例分析
-
PHP中__FILE__、dirname与basename用法实例分析
-
Python中字典的浅拷贝与深拷贝用法实例分析