我在滚动窗格(gbc_constraints)中有一个gbc_constraints,通过单击按钮,文件选择器窗口应该打开,然后用户选择一个JxTreeTable文件,该文件应该被解析为一个新的JxTreeTable。我想用新的代替旧的。但我在努力让这些变化变得显而易见。程序不会明显地调整树,也不会刷新或重新绘制树。我希望你能帮助我。
public class pnlXMLTree extends JPanel {
public TreeTable treeTable;
public JScrollPane scrollPane;
public JXTreeTable jxttable;
public pnlXMLTree() {
List<Object[]> content = new ArrayList<>();
final JFileChooser fc = new JFileChooser();
treeTable = new TreeTable(content);
....
jxttable = treeTable.getTreeTable();
scrollPane = new JScrollPane(jxttable);
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
gbc_scrollPane.anchor = GridBagConstraints.NORTH;
gbc_scrollPane.fill = GridBagConstraints.HORIZONTAL;
gbc_scrollPane.gridwidth = 5;
gbc_scrollPane.gridheight = 13;
gbc_scrollPane.gridx = 2;
gbc_scrollPane.gridy = 1;
add(scrollPane, gbc_scrollPane);
...
...
btnOpenXML.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter(
"xml files (*.xml)", "xml");
fc.setFileFilter(xmlfilter);
fc.setDialogTitle("Open schedule file");
// set selected filter
fc.setFileFilter(xmlfilter);
int returnVal = fc.showOpenDialog(null);
String filepath;
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//This is where a real application would open the file.
System.out.println("Opening: " + file.getName() + ".");
filepath = file.getAbsolutePath();
jxttable = treeTable.getTreeTable(filepath);
//scrollPane = new JScrollPane(treeTable.getTreeTable(filepath));
//jxttable.getModel().getRow(0).;
} else {
System.out.println("Open command cancelled by user.");
}
}
});
setVisible(true);
}
}发布于 2015-08-06 14:03:05
对于JXTreeTable,我总是有同样的问题,解决方案似乎是像这样重置模型:
myTree.setTreeTableModel(new MyTreeTableModel(rootNode));在这个例子中,我的模型构造器以TreeNode类型的根树节点作为参数。
https://stackoverflow.com/questions/31855734
复制相似问题