Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java; JTree; setUI; problem

  • 27-10-2007 05:13PM
    #1
    Closed Accounts Posts: 362 ✭✭


    Does anyone know what might be causing this problem off hand,
    I will post up the code on Monday.

    I bought a JTree UI which looks exactly the way I want, coder now uncontactable.

    But it has stopped the folders in the tree expanding when you click them.

    ie
    +-My Documents
    I have to click the + sign to expand the folder, just clicking My Documents
    does nothing, if I don't add the UI it will expand when I click My Documents

    The JTree UI is a class that extends BasicTreeUI
    Implemented by tree.setUI(new CleanTreeUI());


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    People would really need to see your code before the could tell what's wrong.


  • Closed Accounts Posts: 362 ✭✭information


    I fixed the problem.

    By reading the code I tracked it down to the line bolded.

    It calls checkForClickInExpandControl which is a BasicTreeUI method,

    that calls isLocationInExpandControl which is a BasicTreeUI method,
    that check to see if the mouse clicks in the toggle area.

    I rewrote this method in the CleanTreeUI to always return true and that fixed the problem.
    There is probably a way to set the toggle area to be the full width, but I have it working now.
    public class MouseHandler extends MouseAdapter implements MouseMotionListener {                
            
            void handleSelection(MouseEvent e) {
                if(tree != null && tree.isEnabled()) {
                    if (isEditing(tree) && tree.getInvokesStopCellEditing() && !stopEditing(tree)) {
                        return;
                    }
                    
                    if (tree.isRequestFocusEnabled()) {
                        tree.requestFocus();
                    }
                    TreePath path = getClosestPathForLocation(tree, e.getX(), e.getY());
                    
                    if (path != null) {
                        Rectangle bounds = getPathBounds(tree, path);
                        
                        if(e.getY() > (bounds.y + bounds.height)) {
                            return;
                        }
                        if(SwingUtilities.isLeftMouseButton(e) && e.getID() == MouseEvent.MOUSE_PRESSED) {
                            [B]checkForClickInExpandControl(path, e.getX(), e.getY());[/B]
                        }
    


Advertisement