Skip to content

Commit

Permalink
workaround for primary MacOS bug with accessible context for JTree
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Jun 14, 2024
1 parent fb0b562 commit 2126ba9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/studio/ui/ServerList.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import studio.kdb.Server;
import studio.kdb.ServerTreeNode;

import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
Expand Down Expand Up @@ -311,6 +313,23 @@ private void actionToggleButton() {
private void initComponents() {
treeModel = new DefaultTreeModel(new ServerTreeNode(), true);
tree = new JTree(treeModel) {

/* Override the default behaviour. This is to workaround a strange bug which I met in MacOS with
big tree (few thousands nodes overall). From time to time, the whole UI is frozen for minutes.
*/
@Override
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJTree() {
@Override
public AccessibleRole getAccessibleRole() {
return AccessibleRole.FILLER;
}
};
}
return accessibleContext;
}

@Override
public String convertValueToText(Object nodeObj, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
ServerTreeNode node = (ServerTreeNode) nodeObj;
Expand All @@ -324,6 +343,7 @@ public String convertValueToText(Object nodeObj, boolean selected, boolean expan
value = "<html><b>" + value + "</b></html>";
}
return value;

}
};
tree.setRootVisible(false);
Expand Down

0 comments on commit 2126ba9

Please sign in to comment.