Java Treeview问题

hyrongg 2008-04-30 03:44:52
谁有JAVA TREEVIEW的例子?急,

我用的是JDEVELOPER,不是ECLIPS.

谢谢.
...全文
225 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gambler 2011-07-24
  • 打赏
  • 举报
回复
package isearch.swust.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("isearch3")
@Controller()
@Scope("prototype")

public class ThesauruscategoryAction extends ActionSupport {
private String id;
private String text;
private boolean hasChildren;
private boolean isexpand;//
private boolean complete;//是否展开子节点
private String value;
private List<ThesauruscategoryAction> ChildrenNodes;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public boolean isHasChildren() {
return hasChildren;
}
public void setHasChildren(boolean hasChildren) {
this.hasChildren = hasChildren;
}
public boolean isIsexpand() {
return isexpand;
}
public void setIsexpand(boolean isexpand) {
this.isexpand = isexpand;
}
public boolean isComplete() {
return complete;
}
public void setComplete(boolean complete) {
this.complete = complete;
}

public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public List<ThesauruscategoryAction> getChildrenNodes() {
return ChildrenNodes;
}
public void setChildrenNodes(List<ThesauruscategoryAction> childrenNodes) {
ChildrenNodes = childrenNodes;
}

@Action(value="sendNode",results={
@Result(name="success",type="json")
})
public String sendNode(){
List<ThesauruscategoryAction> list=new ArrayList<ThesauruscategoryAction>();
ThesauruscategoryAction tree1 = new ThesauruscategoryAction();//root
tree1.setId("1");
tree1.setText("中国");
tree1.setHasChildren(true);
tree1.setIsexpand(false);
tree1.setComplete(false);//root
tree1.setValue("86");
List<ThesauruscategoryAction> tree = new ArrayList<ThesauruscategoryAction>();//children

tree1.setChildrenNodes(tree);

ThesauruscategoryAction tree2 = new ThesauruscategoryAction();//firstchild
ThesauruscategoryAction tree3 = new ThesauruscategoryAction();//secondchild
ThesauruscategoryAction tree4 = new ThesauruscategoryAction();//thirdchild

tree2.setId("0.1");
tree2.setText("北京");
tree2.setHasChildren(true);
tree2.setIsexpand(false);
tree2.setComplete(false);
tree2.setValue("1");
tree3.setId("0.2");
tree3.setText("上海");
tree3.setHasChildren(false);
tree3.setIsexpand(false);
tree3.setComplete(false);
tree3.setValue("2");
tree4.setId("0.3");
tree4.setText("天津");
tree4.setHasChildren(false);
tree4.setIsexpand(false);
tree4.setComplete(false);
tree4.setValue("3");

tree.add(tree2);
tree.add(tree3);
tree.add(tree4);

List<ThesauruscategoryAction> tree21 = new ArrayList<ThesauruscategoryAction>();
tree2.setChildrenNodes(tree21);
ThesauruscategoryAction tr1= new ThesauruscategoryAction();
ThesauruscategoryAction tr2 = new ThesauruscategoryAction();
tr1.setId("1.1");
tr1.setText("东城区");
tr1.setHasChildren(false);
tr1.setIsexpand(false);
tr1.setComplete(false);
tr1.setValue("11");
tr2.setId("1.2");
tr2.setText("海淀区");
tr2.setHasChildren(false);
tr2.setIsexpand(false);
tr2.setComplete(false);
tr2.setValue("12");
tree21.add(tr1);
tree21.add(tr2);


list.add(tree1);//putRoot

Gson gson=new Gson();
String json=gson.toJson(list);
System.out.println(tree1);
System.out.println(json);//json格式
System.out.println(list);
System.out.println(gson);

SendJson.send(ServletActionContext.getResponse(), list);
return SUCCESS;
}
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧