From: James Procter Date: Mon, 13 Nov 2023 17:18:14 +0000 (+0000) Subject: JAL-4336 set preferred dimensions for JTextBox workaround in JalviewJS X-Git-Tag: Release_2_11_4_0~89 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=802a1c907dd807ed28f352e944f5091ef4795760;p=jalview.git JAL-4336 set preferred dimensions for JTextBox workaround in JalviewJS --- 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() {