I have a Swing app (residing in an executable, signed jar) that is a client. The app also connects to a server. When certain conditions are met, I perform a refresh of the GUI (more specifically, delete all nodes of a JTree
and then repopulate it). When I run this client as-is (i.e., without a security manager and without residing in an executable, signed JAR), the tree refreshes and updates without any issue.
However, when I package my client as a signed JAR (with the appropriate policy file), I get refresh issues. When the app starts up, I my JTree
is not expanded. When I click it once, it looks like it has expanded, but the child nodes do not show. I have to click it twice after that for the nodes to show. Also, when I perform a refresh (deleting all nodes and then repopulating), the UI doesn't refresh appropriately. I (again) have to click the root-node twice to refresh the GUI.
I tried adding AWT permissions to the policy file, but that didn't help (I wasn't seeing any permission-violations in the first place, but I thought I'd try). I even tried giving the JAR all permissions. That didn't seem to help either. What could be causing this?
The code that performs the refresh is as follows:
private void buildTree() throws IOException, ClassNotFoundException {
setVisible(false);
tree.removeTreeWillExpandListener(this);
tree.removeTreeSelectionListener(this);
DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();
root.removeAllChildren();
root.setUserObject(base);
Book[] bookArray = remoteLibraryService.getAllBooks();
TreeBuilderService.buildTree(root, bookArray);
treeModel.reload();
for(int i = 0; i < tree.getRowCount(); i++) {
tree.expandRow(i);
}
tree.addTreeSelectionListener(this);
tree.addTreeWillExpandListener(this);
setVisible(true);
}
The code that populates the tree (showing just the relevant snippet):
categoryNode = new DefaultMutableTreeNode(book.getGenre());
root.add(categoryNode);
This probably isn't a deal-breaker as far as the assignment is concerned, but it is really bothering me; I'd like to figure out what's causing it.