working on line height issues with #4936

This commit is contained in:
Ben Fry
2017-04-22 18:32:42 -04:00
parent 7c71ad8544
commit a3e7bc90ff
2 changed files with 56 additions and 0 deletions
@@ -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));
@@ -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);
}
}