This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 240705 - Enhance BeanTreeView to allow developers to set the row height
Summary: Enhance BeanTreeView to allow developers to set the row height
Status: NEW
Alias: None
Product: platform
Classification: Unclassified
Component: Explorer (show other bugs)
Version: 7.4
Hardware: All All
: P3 normal with 1 vote (vote)
Assignee: Jan Peska
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-20 13:40 UTC by jmborer
Modified: 2014-01-30 13:57 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jmborer 2014-01-20 13:40:43 UTC
We had an interesting thread exchange (http://forums.netbeans.org/topic58517.html)

I would like an enhancement of TreeView allowing me to override ExplorerTree.calcRowHeight() implementation. A solution would be that calcRowHeight() of the inner ExplorerTree class calls a another overridable method in TreeView. This own, by default, returns the default implementation.  

I am not expecting this method to be invoked for each row. This would allow me to adapt the row height at runtime and not beeing stuck with a system property that is read once at initialization of the VM and applies to all TreeViews. A simple warning to the developer, that returning 0 in size method could have a serious performance impact would be fine IMHO, but at least you leave the decision to her/him. 

I am thinking about something like...

public class TreeView {

      protected int getDefaultRowHeight(Graphics g) {
           return Math.max(18, 2 + g.getFontMetrics(getFont()).getHeight());
       }


      private final class ExplorerTree extends JTree implements Autoscroll, QuickSearch.Callback {

          private void calcRowHeight(Graphics g) {
            // patch here
            int height = getDefaultRowHeight(Graphics g);
           // end patch

            //Issue 42743/"Jesse mode"
            String s = System.getProperty("nb.cellrenderer.fixedheight"); //NOI18N

            if (s != null) {
                try {
                    height = Integer.parseInt(s);
                } catch (Exception e) {
                    //do nothing, height not changed
                }
            }

            if (getRowHeight() != height) {
	        setRowHeight(height);
            } else {
                revalidate();
                repaint();
            }
      }
}        

I am convinced that overriding ExplorerTree.calcRowHeight()  would have no impact on performance, but would be a great improvement when using TreeViews with custom renderers.
Comment 1 jmborer 2014-01-30 13:57:08 UTC
Here is another alternative for setting configurable row height for Tree that won't affect the code structure. It uses client property:

public class TreeView {

      protected int getDefaultRowHeight(Graphics g) {
           return Math.max(18, 2 + g.getFontMetrics(getFont()).getHeight());
       }


      private final class ExplorerTree extends JTree implements Autoscroll, QuickSearch.Callback {
...
        private void calcRowHeight(Graphics g) {
            int height = Math.max(18, 2 + g.getFontMetrics(getFont()).getHeight());

            Object o = super.getClientProperty("row.height");
            if (o != null && o instanceof Number) {
                height = Number.class.cast(o).intValue();
            }

            //Issue 42743/"Jesse mode"
            String s = System.getProperty("nb.cellrenderer.fixedheight"); //NOI18N

            if (s != null) {
                try {
                    height = Integer.parseInt(s);
                } catch (Exception e) {
                    //do nothing, height not changed
                }
            }

            if (getRowHeight() != height) {
	        setRowHeight(height);
            } else {
                revalidate();
                repaint();
            }
        }
...
     }
}