JAL-4336 set preferred dimensions for JTextBox workaround in JalviewJS
authorJames Procter <j.procter@dundee.ac.uk>
Mon, 13 Nov 2023 17:18:14 +0000 (17:18 +0000)
committerJames Procter <j.procter@dundee.ac.uk>
Mon, 13 Nov 2023 17:18:14 +0000 (17:18 +0000)
src/jalview/io/cache/JvCacheableInputBox.java

index e4e2d99..be6ec37 100644 (file)
  */
 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<E>
     {
       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() {