Skip to content

Commit 2fa2059

Browse files
committed
working on line height issues with #4936
1 parent 599671d commit 2fa2059

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

app/src/processing/app/ui/ExamplesFrame.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ public void treeCollapsed(TreeExpansionEvent event) {
183183
tree.setToggleClickCount(1);
184184
}
185185

186+
// Special cell renderer that takes the UI zoom into account
187+
tree.setCellRenderer(new ZoomTreeCellRenderer());
188+
186189
JScrollPane treePane = new JScrollPane(tree);
187190
treePane.setPreferredSize(new Dimension(250, 300));
188191
treePane.setBorder(new EmptyBorder(2, 0, 0, 0));
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
3+
/*
4+
Part of the Processing project - http://processing.org
5+
6+
Copyright (c) 2017 The Processing Foundation
7+
8+
This program is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation; either version 2 of the License, or
11+
(at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with this program; if not, write to the Free Software Foundation,
20+
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21+
*/
22+
23+
package processing.app.ui;
24+
25+
import java.awt.Component;
26+
27+
import javax.swing.JTree;
28+
import javax.swing.tree.DefaultTreeCellRenderer;
29+
30+
31+
class ZoomTreeCellRenderer extends DefaultTreeCellRenderer {
32+
33+
@Override
34+
public Component getTreeCellRendererComponent(JTree tree, Object value,
35+
boolean selected,
36+
boolean expanded,
37+
boolean leaf, int row,
38+
boolean hasFocus) {
39+
40+
// Adjust height for magnified displays. The font is scaled properly,
41+
// but the rows don't automatically use the scaled preferred size.
42+
// https://github.com/processing/processing/issues/4936
43+
int high = getPreferredSize().height;
44+
if (high != 0) {
45+
int current = getSize().height;
46+
if (current != high) {
47+
tree.setRowHeight(high);
48+
}
49+
}
50+
return super.getTreeCellRendererComponent(tree, value, selected,
51+
expanded, leaf, row, hasFocus);
52+
}
53+
}

0 commit comments

Comments
 (0)