CheckBoxTree does not use TristateCheckBox

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

CheckBoxTree does not use TristateCheckBox

Postby pvbemmel » Thu May 24, 2012 5:42 am

I've got a small program FileTreeFrame, that uses a CheckBoxTree with a FileSystemModel .

The checkboxes appear to be normal JCheckBox and not the TristateCheckBox:
  • All checkboxes in the tree show either "selected" (white background, with "V") or "unselected" (white background only),
    even when they should show "mixed" because only a descendant was selected.
  • Once a node is selected using the mouse, none of its descendants can be unselected; i.e. when you click
    on the checkbox of a descendant, the checkbox remains selected.

Note that FileSystemModel never changes, so valueForPathChanged, addTreeModelListener, removeTreeModelListener
are just stubs.

I link with Common Layer source code that I got recently from the subversion repository; it's revision 2138 .

Am I missing something simple here? Any help is appreciated.

Paul van Bemmelen.

Code: Select all

import java.io.*;

import javax.swing.*;
import com.jidesoft.swing.*;

@SuppressWarnings("serial")
public class FileTreeFrame extends JFrame {
  private CheckBoxTree fileTree;

  private FileSystemModel fileSystemModel;

  public FileTreeFrame(String directory) {
    super("JTree FileSystem Viewer");
    fileSystemModel = new FileSystemModel(new File(directory));
    fileTree = new CheckBoxTree(fileSystemModel) {
      public String convertValueToText(Object value, boolean selected,
          boolean expanded, boolean leaf, int row, boolean hasFocus) {
        return ((File)value).getName();
      }
    };
    fileTree.setEditable(false);
    fileTree.getCheckBoxTreeSelectionModel().setDigIn(true);
    getContentPane().add(new JScrollPane(fileTree));
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(640, 480);
    setLocationRelativeTo(null);
    setVisible(true);
  }
  public static void main(String args[]) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e) {
          e.printStackTrace();
        }
        new FileTreeFrame("c:\\");
      }
    });
  }
}

Code: Select all
import java.io.*;

import javax.swing.event.*;
import javax.swing.tree.*;

public class FileSystemModel implements TreeModel {
  private File root;

  public FileSystemModel(File rootDirectory) {
    root = rootDirectory;
  }
  public Object getRoot() {
    return root;
  }
  public Object getChild(Object parent, int index) {
    File directory = (File) parent;
    String[] children = directory.list();
    return new File(directory, children[index]);
  }
  public int getChildCount(Object parent) {
    File file = (File) parent;
    if (file.isDirectory()) {
      String[] fileList = file.list();
      if (fileList != null)
        return file.list().length;
    }
    return 0;
  }
  public boolean isLeaf(Object node) {
    File file = (File) node;
    return file.isFile();
  }
  public int getIndexOfChild(Object parent, Object child) {
    File directory = (File) parent;
    File file = (File) child;
    String[] children = directory.list();
    for (int i = 0; i < children.length; i++) {
      if (file.getName().equals(children[i])) {
        return i;
      }
    }
    return -1;
  }
  public void valueForPathChanged(TreePath path, Object value) {
    System.out.println("valueForPathChanged(...)");
  }
  public void addTreeModelListener(TreeModelListener listener) {
    // do nothing: model never changes.
  }
  public void removeTreeModelListener(TreeModelListener listener) {
    // do nothing: model never changes.
  }
}
pvbemmel
 
Posts: 13
Joined: Thu May 24, 2012 4:32 am

Re: CheckBoxTree does not use TristateCheckBox

Postby JIDE Support » Thu May 24, 2012 8:52 am

Please invoke the following code after you set L&F to install the configurations needed for JIDE components.
Code: Select all
            LookAndFeelFactory.installJideExtension();

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree does not use TristateCheckBox

Postby pvbemmel » Fri May 25, 2012 1:58 am

Thanks for your suggestion:

When I add the line
LookAndFeelFactory.installJideExtension();

I do get the tristate checkbox.

But the checkboxtree behaviour is not the behaviour that I want, and worse: it's erratic.

Based on the behaviour I saw in the JIDE Products demo, I expected the behaviour to be:
  • clicking on a node that is mixed or unselected: the node and all its descendants becomes selected
    , and ancestors become mixed or selected based on whether they have any (other) descendants that are unselected.
  • clicking on a node that is selected: the node and all its descendants becomes unselected
    , and ancestors become mixed or unselected based on whether they have any (other) descendants that are selected.
Instead, I observe behaviour where a descendant can not be unselected if its parent is selected.
And sometimes, when I select a directory, its parent also becomes selected, where the parent should have become mixed.

Example of erratic behaviour:
If in a tree with nothing selected, I click on C:/cygwin/home/p.vanbemmelen , then C:/cygwin/home also becomes selected,
where it should have become mixed. C:/cygwin correctly becomes mixed.
Clicking on C:/cygwin/home/p.vanbemmelen to try to deselect it, will have no effect. Clicking on C:/cygwin/home will deselect
that node and all its descendants.

Example of correct behaviour:
If in a tree with nothing selected, I click on C:/cygwin/home/p.vanbemmelen/java/allen-holub , then C:/cygwin/home/p.vanbemmelen/java/allen-holub
and descendants become selected, and C:/cygwin/home/p.vanbemmelen/java correctly becomes mixed. This is exactly what I want.

Why it works correctly for one dir, and not for another, I have no clue.

Note: the SystemLookAndFeel that the program installs, is "Windows" .
Note: This time I've linked with JIDE Common Layer source obtained from https://github.com/jidesoft/jide-oss (as jidesoft-jide-oss-09b8e50.zip)
I've compiled that code in Eclipse, without using the supplied build.xml (; it compiles just fine).
Note: The behaviour described above is on Windows 7 .

Some more help would be greatly appreciated,

Paul van Bemmelen.
pvbemmel
 
Posts: 13
Joined: Thu May 24, 2012 4:32 am

Re: CheckBoxTree does not use TristateCheckBox

Postby pvbemmel » Fri May 25, 2012 2:18 am

I was wrong: the erratic behaviour I describe is NOT erratic: it's correct.
C:/cygwin/home/p.vanbemmelen is the only descendant of C:/cygwin/home ; so selecting C:/cygwin/home/p.vanbemmelen will also select its parent.
C:/cygwin/home/p.vanbemmelen/java/allen-holub is not the only descendant of C:/cygwin/home/p.vanbemmelen/java , therefore, selecting it will make its parent mixed.

Only remaining problem:
I can't deselect a node if its parent is selected.
pvbemmel
 
Posts: 13
Joined: Thu May 24, 2012 4:32 am

Re: CheckBoxTree does not use TristateCheckBox

Postby JIDE Support » Fri May 25, 2012 11:52 am

It is caused by the fact that you return different File instances for two same queries at FileSystemModel#getChild(). This makes CheckBoxTree fail to determine if those two File instances are equal. We will fix it in next regular release. However, it's highly recommended that you have a cache to make sure the same query returns the same instance. In that way, the risk of memory leak will also be low. The modified test case is attached FYI.

Thanks,
Attachments
FileSystemModel.java
(2.37 KiB) Downloaded 1875 times
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree does not use TristateCheckBox

Postby pvbemmel » Sat May 26, 2012 11:18 am

Great, works like a charm!

Thanks for your great support on a great component.

Paul van Bemmelen.
pvbemmel
 
Posts: 13
Joined: Thu May 24, 2012 4:32 am

Re: CheckBoxTree does not use TristateCheckBox

Postby JIDE Support » Wed May 30, 2012 9:52 am

Just so you know, this is fixed in 3.4.1 just released.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree does not use TristateCheckBox

Postby geetesh » Tue Aug 14, 2012 1:09 am

Hi,

I Know this post is quite old but I am facing a similar issue.
I am using version 3.4.4.
I was just trying a demo application. The CheckBox only has two states.
Code: Select all

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.swing.CheckBoxTree;


public class Test {
   
   Test(){
      JFrame frame=new JFrame();
      JPanel panel=new JPanel();
      
      
      frame.add(panel);
      
      CheckBoxTree check=new CheckBoxTree();
      panel.add(check);
      check.getCheckBoxTreeSelectionModel().setDigIn(true);
      check.setCheckBoxEnabled(true);
      check.setEnabled(true);
      check.setRootVisible(false);
      check.setShowsRootHandles(true);
      //chec
      frame.pack();
      frame.setVisible(true);
   }
   public static void main(String[] args) {
       SwingUtilities.invokeLater(new Runnable() {
               public void run() {
                  LookAndFeelFactory.installJideExtension();
                   new Test();
               }
           });
      
      
   }

}


Any Help will be highly appreciated.

Thanks,
Geetesh
geetesh
 
Posts: 3
Joined: Tue Aug 14, 2012 1:02 am

Re: CheckBoxTree does not use TristateCheckBox

Postby pvbemmel » Tue Aug 14, 2012 4:22 am

If you add
Code: Select all
        try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e) {
          e.printStackTrace();
        }

just before the line
LookAndFeelFactory.installJideExtension();
then, on Windows, you will get the tristate checkboxes.
It looks like it has been implemented for the Windows LookAndFeel and not for the default Metal LookAndFeel.
pvbemmel
 
Posts: 13
Joined: Thu May 24, 2012 4:32 am

Re: CheckBoxTree does not use TristateCheckBox

Postby geetesh » Tue Aug 14, 2012 4:39 am

Thanks for your help. The problem is not yet resolved though :)

Actually the Third state that I am looking for is a check box with a painted rectangle in between just as is shown in the demo.

What I am getting currently is A highlighted checkbox with a tick mark inside it.

I want to implement it for Metal Look and Feel as well.......
geetesh
 
Posts: 3
Joined: Tue Aug 14, 2012 1:02 am

Re: CheckBoxTree does not use TristateCheckBox

Postby pvbemmel » Tue Aug 14, 2012 7:32 am

Here is what I get:
screendump.JPG
Test program showing CheckBoxTree
screendump.JPG (10.84 KiB) Viewed 49446 times

Is that what you have?
pvbemmel
 
Posts: 13
Joined: Thu May 24, 2012 4:32 am

Re: CheckBoxTree does not use TristateCheckBox

Postby JIDE Support » Tue Aug 14, 2012 9:28 am

Hi Geetesh,

Tested the test case you posted with 3.4.4. It looks fine in both L&Fs on our end. Snapshot attached FYI.
Could you please post a snapshot and double check the release you are using?

Thanks,
Attachments
checkboxtree.png
checkboxtree.png (26.17 KiB) Viewed 49444 times
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree does not use TristateCheckBox

Postby pvbemmel » Tue Aug 14, 2012 10:45 am

You are right: on my machine default L&F also looks fine , like your image on the left.

I think I got confused: it is only when I omit
LookAndFeelFactory.installJideExtension();
that it does not show tristate checkbox.
pvbemmel
 
Posts: 13
Joined: Thu May 24, 2012 4:32 am

Re: CheckBoxTree does not use TristateCheckBox

Postby JIDE Support » Tue Aug 14, 2012 10:51 am

May I ask which L&F you are using? Anyway, the correct order should be installing the LnF, installing the JIDE extension, instantiating JIDE components. Please check if you could still see the issue with that order.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree does not use TristateCheckBox

Postby geetesh » Thu Aug 16, 2012 2:54 am

Hello Team,

I am doing this :
Code: Select all
 SwingUtilities.invokeLater(new Runnable() {
               public void run() {
                  try {
                     LookAndFeelFactory.installJideExtension();
                      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                     }
                     catch (Exception e) {
                       e.printStackTrace();
                     }
                  LookAndFeelFactory.installJideExtension();
                  
                   new Test();
               }
           });

In my test constructor I am invoking Jide components like this :
Code: Select all
   Test(){
      JFrame frame=new JFrame();
      JPanel panel=new JPanel();
      
      
      frame.add(panel);
      
      CheckBoxTree check=new CheckBoxTree();
      panel.add(check);
      check.getCheckBoxTreeSelectionModel().setDigIn(true);
      check.setCheckBoxEnabled(true);
      check.setEnabled(true);
      check.setRootVisible(false);
      check.setShowsRootHandles(true);
      
      frame.pack();
      frame.setVisible(true);
   }


But the Tristaate is not getting reflected as expected. It is as follows:

Without
Code: Select all
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
I am getting
trustate.jpg
First Snapshot
trustate.jpg (20.73 KiB) Viewed 49437 times


With
Code: Select all
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
I am getting
tristate.jpg
Second Snapshot
tristate.jpg (18.76 KiB) Viewed 49437 times


Now what I want is when I select a child the parent that is semi selected should show a check filled with a rectangle instead of the TIck Mark
Something like this (The ones marked by red rectangles):
example.png
example.png (30.99 KiB) Viewed 49437 times





Thanks in advance,
Geetesh
geetesh
 
Posts: 3
Joined: Tue Aug 14, 2012 1:02 am

Re: CheckBoxTree does not use TristateCheckBox

Postby JIDE Support » Thu Aug 16, 2012 9:50 am

Hi geetesh,

It looks like that "TristateCheckBox.icon" was somehow missed in UIDefaults. Please make a check.
B.T.W, please make sure L&F was installed before installing the Jide extension. Here is a test case FYI.
Code: Select all
/*
 * @(#)TristateTest.java 8/16/2012
 *
 * Copyright 2002 - 2012 JIDE Software Inc. All rights reserved.
 */

import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.swing.CheckBoxTree;

import javax.swing.*;

/**
 * Created with IntelliJ IDEA. User: JIDE-010 Date: 8/16/12 Time: 9:20 AM To change this template use File | Settings |
 * File Templates.
 */
public class TristateTest {

    public static void main(String[] argv) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    LookAndFeelFactory.installJideExtension();
                    System.out.println(UIManager.getDefaults().getIcon("TristateCheckBox.icon"));
                }
                catch (Exception e) {
                    e.printStackTrace();
                }

                JFrame frame=new JFrame();
                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                JPanel panel=new JPanel();


                frame.add(panel);

                CheckBoxTree check=new CheckBoxTree();
                panel.add(check);
                check.getCheckBoxTreeSelectionModel().setDigIn(true);
                check.setCheckBoxEnabled(true);
                check.setEnabled(true);
                check.setRootVisible(false);
                check.setShowsRootHandles(true);

                frame.pack();
                frame.setVisible(true);
            }
        });
    }

}


Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: Google [Bot] and 10 guests

cron