From 802a1c907dd807ed28f352e944f5091ef4795760 Mon Sep 17 00:00:00 2001 From: James Procter Date: Mon, 13 Nov 2023 17:18:14 +0000 Subject: [PATCH] JAL-4336 set preferred dimensions for JTextBox workaround in JalviewJS --- src/jalview/io/cache/JvCacheableInputBox.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/jalview/io/cache/JvCacheableInputBox.java b/src/jalview/io/cache/JvCacheableInputBox.java index e4e2d99..be6ec37 100644 --- a/src/jalview/io/cache/JvCacheableInputBox.java +++ b/src/jalview/io/cache/JvCacheableInputBox.java @@ -20,10 +20,8 @@ */ package jalview.io.cache; -import jalview.bin.Cache; -import jalview.util.MessageManager; -import jalview.util.Platform; - +import java.awt.Dimension; +import java.awt.FontMetrics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusListener; @@ -47,6 +45,10 @@ import javax.swing.event.CaretListener; import javax.swing.event.DocumentListener; import javax.swing.text.JTextComponent; +import jalview.bin.Cache; +import jalview.util.MessageManager; +import jalview.util.Platform; + /** * A class that provides an editable combobox with a memory of previous entries * that may be persisted @@ -114,6 +116,9 @@ public class JvCacheableInputBox { appCache = null; textComponent = textField = new JTextField(); + FontMetrics fm = textField.getFontMetrics(textField.getFont()); + textField.setPreferredSize(new Dimension( + fm.stringWidth(prototypeDisplayValue), fm.getHeight() + 4)); // { // @Override // public Dimension getPreferredSize() { -- 1.7.10.2