我需要为我的程序显示帐户名称,并且我想在 JScrollPane 中使用 JTree 来执行此操作。
这是我的代码:
public void loadAccounts() {
accountsRoot = new DefaultMutableTreeNode("Accounts"); //create root
accountsRoot.add(new DefaultMutableTreeNode("Fred")); //add one element
//for testing
accounts = new JTree(accountsRoot);
accountsPane = new JScrollPane(accounts);
accountsPane.add(accounts); //don't think this is necessary
canvas.add(accountsPane);
accounts.setBounds(0, 0, accountsPane.getWidth(), accountsPane.getHeight());
accountsPane.setBounds(460, 270, 240, 410);
accounts.setVisible(true);
accountsPane.setVisible(true);
}
因为我没有使用布局,所以我手动设置了边界。
我似乎无法让它显示出来。我想最终从一段时间内加载帐户,所以我认为 JTree 会很容易,