From: Niki Roo Date: Thu, 23 May 2019 07:51:07 +0000 (+0200) Subject: ConfigItem: assure label placement if taller pane X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=e95f4fb6e42ae31c2353a31aca79ecf68ee6a014;p=fanfix-jexer.git ConfigItem: assure label placement if taller pane --- diff --git a/src/be/nikiroo/utils/ui/ConfigItem.java b/src/be/nikiroo/utils/ui/ConfigItem.java index 14348b6..4633370 100644 --- a/src/be/nikiroo/utils/ui/ConfigItem.java +++ b/src/be/nikiroo/utils/ui/ConfigItem.java @@ -51,6 +51,8 @@ import be.nikiroo.utils.resources.MetaInfo; public class ConfigItem> extends JPanel { private static final long serialVersionUID = 1L; + private static int minimumHeight = -1; + /** A small (?) blue in PNG, base64 encoded. */ private static String infoImage64 = // "" @@ -444,6 +446,8 @@ public class ConfigItem> extends JPanel { ps = label.getSize(); } + ps.height = Math.max(ps.height, getMinimumHeight()); + int w = ps.width; int step = 150; for (int i = 2 * step - nhgap; i < 10 * step; i += step) { @@ -498,13 +502,16 @@ public class ConfigItem> extends JPanel { pane2.add(help, BorderLayout.WEST); pane2.add(new JLabel(" "), BorderLayout.CENTER); - JPanel pane = new JPanel(new BorderLayout()); - pane.add(label, BorderLayout.WEST); - pane.add(pane2, BorderLayout.CENTER); + JPanel contentPane = new JPanel(new BorderLayout()); + contentPane.add(label, BorderLayout.WEST); + contentPane.add(pane2, BorderLayout.CENTER); ps.width = w + 30; // 30 for the (?) sign - pane.setSize(ps); - pane.setPreferredSize(ps); + contentPane.setSize(ps); + contentPane.setPreferredSize(ps); + + JPanel pane = new JPanel(new BorderLayout()); + pane.add(contentPane, BorderLayout.NORTH); return pane; } @@ -548,9 +555,16 @@ public class ConfigItem> extends JPanel { } private void setPreferredSize(JComponent field) { - JTextField a = new JTextField("Test"); - int height = Math.max(a.getMinimumSize().height, - field.getMinimumSize().height); + int height = Math + .max(getMinimumHeight(), field.getMinimumSize().height); setPreferredSize(new Dimension(200, height)); } + + static private int getMinimumHeight() { + if (minimumHeight < 0) { + minimumHeight = new JTextField("Test").getMinimumSize().height; + } + + return minimumHeight; + } }