NetBeans OutlineView Filtering

Leave a comment

September 7, 2012 by huionn

Today I read that Windows 7 Explorer provides many powerful tools for searching, grouping and filtering I am not sure how many advanced Windows users are using those features, but I am interested in its header filtering.


A drop down menu is available in Explore header for filtering. A tick is shown if the column has filter.

Therefore I tried to mimic the user interface in my application. Thankfully, someone shared a working example for JTable at What I need to do is to port the code for NetBeans’ OutlineView and do some enhancements.



A few issues that I solved:

  1. Clicking the header menu area should not toggle sorting.
    My idea is to detect the mouse event and toggle sorting if the clicked point is not in the menu area. As ETable is not in public API, I have no way to override it for adding MouseListener. After reading the source codes in etable package, the only way I can solve this problem is to do some hacking…
    // NOTE: this is hacking - it is broken if the mouse listeners are updated
    for (MouseListener l : mouseListeners) {
       // wrap org.netbeans.swing.etable.ETable$HeaderMouseListener to 
       // mute mouse click in menu area
       if (l.getClass().getSimpleName().equals("HeaderMouseListener")) {
           header.addMouseListener(new MenuHeaderMouseListener(l));

    I wrap the ETable$HeaderMouseListener with my mouse listener (Decorator pattern) and delegate the action to HeaderMouseListener only if the click is not in header menu area. As I put in my comment, this is just hacking as it will break if someone update the mouse listener later.

  2. The JPopupMenu should not hide when user click a menu item, as I want it to remain so that user can select multiple menu items.
    The solution is relatively simple (although the road to solution is not straightforward). I just override BasicMenuItemUI with this:
    public class PopupMenuItemUI extends BasicMenuItemUI {
        protected void doClick(MenuSelectionManager msm) {
            // Visual feedback

    and set the UI to menu item. Basically I just remove the code that hide the JPopupMenu (and click sound as the called method is private).

  3. Add a ‘tick’ icon whenever there is any selected JCheckBoxMenuItem
    I just set the icon in table header renderer if there is any selected JCheckBoxMenuItem.


Java Swing architecture is very flexible (I was very surprised when I learnt that Swing components are basically just images with event capture). NetBeans Platform as built on Swing technology, allows customization of user interface easily.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: