zookeeper python接口实例详解
214
2023-07-29
swing中Tree与滚动条用法实例分析
本文实例讲述了swing中Tree与滚动条用法。分享给大家供大家参考。具体如下:
import java.awt.*;
import java.awt.event.*;
import javax.swhttp://ing.*;
import javaIZELWqyx.swing.tree.*;
public class test extends JApplet{
JTree tree;
JTextField jtf;
public void init(){
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
DefaultMutableTreeNodhttp://e 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.CEhttp://NTER);
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程序设计有所帮助。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~