我在NetBeans上创建一个简单的树视图,我想知道如何通过一个具有与标签相关联的函数的按钮向已确定的选定节点添加描述。
Click to see Treeview Image here
该链接通过点击“>>”显示我想要做的图像它会向该标签添加描述并与该选定节点关联。
这是“>>”的代码按钮。
[types] => Array
(
)
[portType] => Array
(
[@attributes] => Array
(
[name] => PullServiceHISPort
)
[operation] => Array
(
[@attributes] => Array
(
[name] => OTA_HotelResRQ
)
[documentation] => This method takes XML request and return a string response
[input] => Array
(
[@attributes] => Array
(
[message] => tns:OTA_HotelResRQIn
)
)
[output] => Array
(
[@attributes] => Array
(
[message] => tns:OTA_HotelResRQOut
)
)
)
)
[binding] => Array
(
[@attributes] => Array
(
[name] => PullServiceHISBinding
[type] => tns:PullServiceHISPort
)
[operation] => Array
(
[@attributes] => Array
(
[name] => OTA_HotelResRQ
)
[input] => Array
(
)
[output] => Array
(
)
)
)
[service] => Array
(
[@attributes] => Array
(
[name] => PullServiceHISService
)
[port] => Array
(
[@attributes] => Array
(
[name] => PullServiceHISPort
[binding] => tns:PullServiceHISBinding
)
)
)
[message] => Array
(
[0] => Array
(
[@attributes] => Array
(
[name] => OTA_HotelResRQIn
)
[0] => Array
(
[@attributes] => Array
(
[name] => bookingRQ
[type] => xsd:string
)
)
)
[1] => Array
(
[@attributes] => Array
(
[name] => OTA_HotelResRQOut
)
[part] => Array
(
[@attributes] => Array
(
[name] => return
[type] => xsd:string
)
)
)
)
显然这不是我想要的,我只是在这里展示我想要的东西。
答案 0 :(得分:0)
您希望为树节点创建自己的类,作为您现在使用的任何子类,在子类中添加description
字段和相应的访问器。例如,如果您使用DefaultMutableTreeNode
:
class MyNode extends DefaultMutableTreeNode {
private String description;
...
public void setDescription(String descr) {
description = descr;
}
public String getDescription() {
return description;
}
}
完成后,在actionPerformed()
中为要获取所选树节点的按钮,从中获取描述,并在标签中设置文本:
private void add2ActionPerformed(java.awt.event.ActionEvent evt)
{
MyNode node = (MyNode)tree.getLastSelectedPathComponent();
String descr = node.getDescription();
lTree2.setztext(descr);
}