mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-09 08:15:09 +03:00
Tree: improved support for JTree.getPathForLocation(int x, int y) in wide selection (issue #373)
this is experimental and disabled by default; enable with: `UIManager.put( "FlatLaf.experimental.tree.widePathForLocation", true );`
This commit is contained in:
@@ -230,6 +230,26 @@ public class FlatTreeUI
|
||||
tree.repaint( 0, r.y, tree.getWidth(), r.height );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getPathBounds( JTree tree, TreePath path ) {
|
||||
Rectangle bounds = super.getPathBounds( tree, path );
|
||||
|
||||
// If this method was invoked from JTree.getPathForLocation(int x, int y) to check whether
|
||||
// the location is within tree node bounds, then return the bounds of a wide node.
|
||||
// This changes the behavior of JTree.getPathForLocation(int x, int y) and
|
||||
// JTree.getRowForLocation(int x, int y), which now return the path/row even
|
||||
// if [x,y] is in the wide row area outside of the actual tree node.
|
||||
if( bounds != null &&
|
||||
isWideSelection() &&
|
||||
UIManager.getBoolean( "FlatLaf.experimental.tree.widePathForLocation" ) &&
|
||||
StackUtils.wasInvokedFrom( JTree.class.getName(), "getPathForLocation", 5 ) )
|
||||
{
|
||||
bounds.x = 0;
|
||||
bounds.width = tree.getWidth();
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as super.paintRow(), but supports wide selection and uses
|
||||
* inactive selection background/foreground if tree is not focused.
|
||||
|
||||
Reference in New Issue
Block a user