GT-3103 - Look and Feel - fixed Linux Nimbus LaF issues with painting

tree row backgrounds
This commit is contained in:
dragonmacher 2019-08-23 14:11:38 -04:00
parent 0084a70f87
commit aa71d84620
6 changed files with 60 additions and 20 deletions

View file

@ -41,10 +41,6 @@ public class GTreeRenderer extends DefaultTreeCellRenderer implements GComponent
setHTMLRenderingEnabled(false);
}
/**
*
* @see javax.swing.tree.DefaultTreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
*/
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected1,
boolean expanded, boolean leaf, int row, boolean hasFocus1) {
@ -56,6 +52,9 @@ public class GTreeRenderer extends DefaultTreeCellRenderer implements GComponent
setText(text);
setToolTipText(node.getToolTip());
setOpaque(true);
setBackground(selected1 ? getBackgroundSelectionColor() : getBackgroundNonSelectionColor());
Icon icon = node.getIcon(expanded);
if (icon == null) {
icon = getIcon();

View file

@ -15,9 +15,9 @@
*/
package ghidra.docking.util;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.*;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;
import javax.swing.*;
@ -206,10 +206,40 @@ public class DockingWindowsLookAndFeelUtils {
// This fix looks like it should not cause harm even if the bug is fixed on the jdk side.
UIDefaults defaults = lookAndFeel.getDefaults();
defaults.put("ScrollBar.minimumThumbSize", new Dimension(30, 30));
UIDefaults lafd = UIManager.getLookAndFeelDefaults();
Painter<JComponent> painterStub = new Painter<>() {
@Override
public void paint(Graphics2D g, JComponent c, int width, int height) {
// stub
}
};
// (see NimbusDefaults for key values)
// These settings disable tree row selection; when enable each tree row paints its
// selection independently from the renderer
lafd.put("Tree:TreeCell[Enabled+Selected].backgroundPainter", painterStub);
lafd.put("Tree:TreeCell[Focused+Selected].backgroundPainter", painterStub);
// These settings force the tree arrow icon painting to use the non-selected
// color. We need this since we disabled the row selection painting above.
swapPainters(lafd, "Tree[Enabled].collapsedIconPainter",
"Tree[Enabled+Selected].collapsedIconPainter");
swapPainters(lafd, "Tree[Enabled].expandedIconPainter",
"Tree[Enabled+Selected].expandedIconPainter");
break;
}
}
private static void swapPainters(UIDefaults lafd, String from, String to) {
@SuppressWarnings("unchecked")
Painter<JComponent> newPainter = (Painter<JComponent>) lafd.get(from);
lafd.put(to, newPainter);
}
private static void installGlobalLookAndFeelAttributes() {
// Fix up the default fonts that Java 1.5.0 changed to Courier, which looked terrible.
Font f = new Font("Monospaced", Font.PLAIN, 12);