【发布时间】:2014-10-13 12:45:21
【问题描述】:
这是我当前的代码 - 它只显示我的 GitCommands.properties 文件中的密钥对值并将其显示在我的 GetAllProperties.java 文件中 - 是否可以对其进行排序,使其进入 JTree 而不仅仅是显示它列表类型格式?
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
public class GetAllProperties {
private static JTree tree;
public static void main(String[] args) {
Properties properties = new Properties();
try {
String filename = "GitCommands.properties";
// File file = new
// File("/ApplicationTest/.settings/GitCommands.properties");
FileInputStream fileInputStream = new FileInputStream(filename);
// load properties file
properties.load(fileInputStream);
System.out.println("keys avialble in Properties Files are:");
System.out.println(properties.keySet());
System.out.println("Key Value Pairs :");
Enumeration enumeration = properties.keys();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
System.out.println(key + ": " + properties.get(key));
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
【问题讨论】:
-
我不确定树是否有意义,但有可能。看看How to Use Trees。
JTable可能更有意义,请参阅 How to Use Tables -
这可能看起来有点奇怪,但我不允许使用一张桌子,它必须是一棵树:(你介意指点我正确的方向吗?我看了很多示例,但尚未遇到将属性文件放入 JTree 的示例,感谢您的回复!
-
嗯,这就是问题所在,什么是节点,什么是叶子?
-
我想要一个名为 GIT commands 的根文件,当单击它时,它会打开以将所有 GIT 命令键显示为节点。然后单击每个单独的节点后,我希望它将同一属性文件中的描述字符串显示到右侧的面板中
标签: java swing jtree properties-file