From 087ba28b821593c843d7ed2c57e1f8287316fb33 Mon Sep 17 00:00:00 2001 From: Seth Morabito Date: Tue, 1 Sep 2020 10:48:17 -0700 Subject: [PATCH] Force metal look-and-feel * On Linux GTK+, the small text fields in the Status Panel displayed a large inner margin, cutting off text. This change forces Java to use the Metal look-and-feel for these fields, which forces no default inner margin. --- src/main/java/com/loomcom/symon/ui/StatusPanel.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/loomcom/symon/ui/StatusPanel.java b/src/main/java/com/loomcom/symon/ui/StatusPanel.java index cd4b75f..f0e10e3 100644 --- a/src/main/java/com/loomcom/symon/ui/StatusPanel.java +++ b/src/main/java/com/loomcom/symon/ui/StatusPanel.java @@ -30,6 +30,7 @@ import com.loomcom.symon.machines.Machine; import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.EtchedBorder; +import javax.swing.plaf.metal.MetalTextFieldUI; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -69,7 +70,7 @@ public class StatusPanel extends JPanel { private JTextField xField; private JTextField yField; - private Machine machine; + private final Machine machine; private static final int EMPTY_BORDER = 10; private static final Border LABEL_BORDER = BorderFactory.createEmptyBorder(0, 5, 0, 0); @@ -392,6 +393,13 @@ public class StatusPanel extends JPanel { textField.setMaximumSize(size); textField.setPreferredSize(size); textField.setBackground(Color.WHITE); + // Although we usually defer to the system look-and-feel, for + // these small text fields in particular, we use a Metal + // look-and-feel because native look-and-feel breaks very small + // text fields under GTK+ (they are drawn with an inner margin + // even if the margin is set to 0) + textField.setUI(new MetalTextFieldUI()); + return textField; }