diff --git a/app/src/processing/app/ui/ExamplesFrame.java b/app/src/processing/app/ui/ExamplesFrame.java index 105858a87..82db81249 100644 --- a/app/src/processing/app/ui/ExamplesFrame.java +++ b/app/src/processing/app/ui/ExamplesFrame.java @@ -183,6 +183,9 @@ public class ExamplesFrame extends JFrame { tree.setToggleClickCount(1); } + // Special cell renderer that takes the UI zoom into account + tree.setCellRenderer(new ZoomTreeCellRenderer()); + JScrollPane treePane = new JScrollPane(tree); treePane.setPreferredSize(new Dimension(250, 300)); treePane.setBorder(new EmptyBorder(2, 0, 0, 0)); diff --git a/app/src/processing/app/ui/ZoomTreeCellRenderer.java b/app/src/processing/app/ui/ZoomTreeCellRenderer.java new file mode 100644 index 000000000..460f11313 --- /dev/null +++ b/app/src/processing/app/ui/ZoomTreeCellRenderer.java @@ -0,0 +1,53 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2017 The Processing Foundation + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package processing.app.ui; + +import java.awt.Component; + +import javax.swing.JTree; +import javax.swing.tree.DefaultTreeCellRenderer; + + +class ZoomTreeCellRenderer extends DefaultTreeCellRenderer { + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, + boolean selected, + boolean expanded, + boolean leaf, int row, + boolean hasFocus) { + + // Adjust height for magnified displays. The font is scaled properly, + // but the rows don't automatically use the scaled preferred size. + // https://github.com/processing/processing/issues/4936 + int high = getPreferredSize().height; + if (high != 0) { + int current = getSize().height; + if (current != high) { + tree.setRowHeight(high); + } + } + return super.getTreeCellRendererComponent(tree, value, selected, + expanded, leaf, row, hasFocus); + } +} \ No newline at end of file