Skip to content

Commit

Permalink
fixed JTree issue with spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasherz committed Dec 22, 2023
1 parent 5402994 commit b333964
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/main/java/de/usd/cstchef/view/OperationsTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.plaf.basic.BasicTreeUI;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
Expand All @@ -30,7 +31,7 @@ public class OperationsTree extends JTree {

public OperationsTree() {
super();

this.setUI(new CustomTreeUI());
this.model = (DefaultTreeModel) this.getModel();
this.model.setRoot(this.createTree());
this.setToolTipText("");
Expand Down Expand Up @@ -67,7 +68,7 @@ public void search(String text) {
}

ArrayList<DefaultMutableTreeNode> nodesToRemove = new ArrayList<>();
Enumeration<TreeNode> e = root.breadthFirstEnumeration();
Enumeration<TreeNode> e = root.breadthFirstEnumeration();
while (e.hasMoreElements()) {
DefaultMutableTreeNode nextNode = (DefaultMutableTreeNode) e.nextElement();
if (!nextNode.toString().toLowerCase().contains(text.toLowerCase())) {
Expand Down Expand Up @@ -96,7 +97,7 @@ public void search(String text) {
this.expandAll(new TreePath(root));
}

private void removeNode(TreeNode selNode) {
private void removeNode(TreeNode selNode) {
if (selNode == null) {
return;
}
Expand All @@ -109,7 +110,7 @@ private void removeNode(TreeNode selNode) {
if (selNode.getChildCount() == 0) {
this.model.removeNodeFromParent((MutableTreeNode) selNode);
}
}
}

private DefaultMutableTreeNode createTree() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
Expand Down Expand Up @@ -157,4 +158,12 @@ private void expandAll(TreePath path) {
}
this.expandPath(path);
}

public class CustomTreeUI extends BasicTreeUI {
@Override
protected boolean shouldPaintExpandControl(javax.swing.tree.TreePath path, int row, boolean isExpanded,
boolean hasBeenExpanded, boolean isLeaf) {
return true; // Always display expand/collapse control
}
}
}
1 change: 0 additions & 1 deletion src/main/java/de/usd/cstchef/view/RecipePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public RecipePanel(BurpOperation operation, MessageType messageType) {
searchTreePanel.add(searchText, BorderLayout.PAGE_START);

OperationsTree operationsTree = new OperationsTree();
operationsTree.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
operationsTree.setRootVisible(false);
searchTreePanel.add(new JScrollPane(operationsTree));
searchText.getDocument().addDocumentListener(new DocumentListener() {
Expand Down

0 comments on commit b333964

Please sign in to comment.