2

Is it possible to remove the dots border for DefaultMutableTreenNode in JTree?

For JButton I use:

JButton btn;
btn.setFocusPainted(false);

But I cannot find an equivalent for DefaultMutableTreenNode.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Fry
  • 6,235
  • 8
  • 54
  • 93

1 Answers1

4

I'm not sure if that is exactly what you are trying to achieve, but try this before you instantiate any swing components:

// For the border around the icon
UIManager.put("Tree.drawsFocusBorderAroundIcon", false);
// Dashed border
UIManager.put("Tree.drawDashedFocusIndicator", false);
Anthony Accioly
  • 21,918
  • 9
  • 70
  • 118
  • Hi Fry, see my update. If it does not work, then please give more details of what you are trying to achieve (with pictures maybe). `DefaultMutableTreeNode`does not draw anything, [DefaultTreeCellRender](http://docs.oracle.com/javase/8/docs/api/javax/swing/tree/TreeCellRenderer.html) does (unless you are using a custom renderer). – Anthony Accioly Mar 28 '14 at 16:13
  • As far as I can tell my [paint](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/javax/swing/tree/DefaultTreeCellRenderer.java#DefaultTreeCellRenderer.paint%28java.awt.Graphics%29) and [paintFocus](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/javax/swing/tree/DefaultTreeCellRenderer.java#DefaultTreeCellRenderer.paintFocus%28java.awt.Graphics%2Cint%2Cint%2Cint%2Cint%2Cjava.awt.Color%29) implementation these are the two underline properties that controls focus drawing. – Anthony Accioly Mar 28 '14 at 16:15
  • Work perfectly, only with the second `UIManager.put("Tree.drawDashedFocusIndicator", false);` – Fry Mar 28 '14 at 16:35
  • Hi Fry, I appreciate your attempt to organize the answer and my later edit, but I have roll backed your proposed changes and added comments to clear what each property does. They both control different aspects of what `DefaultTreeCellRenderer` draws on focus, and since readers of this question may be looking to tweak the focus behavior in different ways, I don't want anyone thinking that `Tree.drawsFocusBorderAroundIcon` does not work (actually, to totally disable the focus indication I think that both properties must be set to `false`). – Anthony Accioly Mar 30 '14 at 21:22