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

Java; JTree; setUI; problem

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