Java 树形问题 很简单 在线等随时给分
现在有个树形结构图在左...然后有个文本框在右当点击右边的树形节点的时候左边文本框则显示“软件设计”当点击右边的树形根节点时则不显示任何文字怎么弄大概就是这个意思树形赋值...
现在有个树形结构图 在左 ... 然后 有个文本框 在右
当点击 右边的 树形节点的时候 左边文本框则显示 “软件设计”
当点击 右边的 树形根节点时 则不显示任何文字怎么弄 大概就是这个意思
树形赋值 展开
当点击 右边的 树形节点的时候 左边文本框则显示 “软件设计”
当点击 右边的 树形根节点时 则不显示任何文字怎么弄 大概就是这个意思
树形赋值 展开
2个回答
展开全部
不知下面这个例子是否会对你有所帮助。
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class 处理树选取事件 extends JApplet {
JTree tree = new JTree();
JTextArea textArea = new JTextArea();
JSplitPane splitPane = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT,
new JScrollPane(tree),
new JScrollPane(textArea));
public void init() {
splitPane.setDividerLocation(150);
textArea.setFont(new Font("Serif", Font.PLAIN, 17));
getContentPane().add(splitPane, BorderLayout.CENTER);
tree.addTreeSelectionListener(
new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
TreePath path = e.getNewLeadSelectionPath();
String s = new String();
if(path != null) {
s += "New lead selection path: " +
path.toString() + "\n";
}
else
s += "selection cleared\n";
path = e.getOldLeadSelectionPath();
if(path != null) {
s += "Old lead selection path: " +
path.toString() + "\n";
}
else
s += "No previous lead selection\n";
textArea.append(s + "\n");
printSelectionInformation(e);
}
void printSelectionInformation(TreeSelectionEvent e) {
showPaths(e);
showRows();
textArea.append("\n----------------------------");
textArea.append("----------------------------\n");
}
private void showPaths(TreeSelectionEvent e) {
TreePath[] paths = e.getPaths();
textArea.append("Number of Paths: " +
paths.length + "\n");
for(int i=0; i < paths.length; ++i) {
TreePath path = paths[i];
boolean wasAdded = e.isAddedPath(path);
textArea.append(" path " + i + ": ");
textArea.append(path +
(wasAdded ? " added to selection" :
" removed from selection") + "\n");
}
}
private void showRows() {
int[] rows = tree.getSelectionRows();
if(rows != null && rows.length > 0) {
textArea.append("\nSelected Rows: ");
for(int i=0; i < rows.length; ++i) {
textArea.append(
Integer.toString(rows[i]));
if(i != rows.length-1)
textArea.append(",");
}
}
}
});
}
}
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class 处理树选取事件 extends JApplet {
JTree tree = new JTree();
JTextArea textArea = new JTextArea();
JSplitPane splitPane = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT,
new JScrollPane(tree),
new JScrollPane(textArea));
public void init() {
splitPane.setDividerLocation(150);
textArea.setFont(new Font("Serif", Font.PLAIN, 17));
getContentPane().add(splitPane, BorderLayout.CENTER);
tree.addTreeSelectionListener(
new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
TreePath path = e.getNewLeadSelectionPath();
String s = new String();
if(path != null) {
s += "New lead selection path: " +
path.toString() + "\n";
}
else
s += "selection cleared\n";
path = e.getOldLeadSelectionPath();
if(path != null) {
s += "Old lead selection path: " +
path.toString() + "\n";
}
else
s += "No previous lead selection\n";
textArea.append(s + "\n");
printSelectionInformation(e);
}
void printSelectionInformation(TreeSelectionEvent e) {
showPaths(e);
showRows();
textArea.append("\n----------------------------");
textArea.append("----------------------------\n");
}
private void showPaths(TreeSelectionEvent e) {
TreePath[] paths = e.getPaths();
textArea.append("Number of Paths: " +
paths.length + "\n");
for(int i=0; i < paths.length; ++i) {
TreePath path = paths[i];
boolean wasAdded = e.isAddedPath(path);
textArea.append(" path " + i + ": ");
textArea.append(path +
(wasAdded ? " added to selection" :
" removed from selection") + "\n");
}
}
private void showRows() {
int[] rows = tree.getSelectionRows();
if(rows != null && rows.length > 0) {
textArea.append("\nSelected Rows: ");
for(int i=0; i < rows.length; ++i) {
textArea.append(
Integer.toString(rows[i]));
if(i != rows.length-1)
textArea.append(",");
}
}
}
});
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询