Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java; JTree; setUI; problem

  • 27-10-2007 4: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