0

How to prevent shrinking JPanel which contains only JFormattedTextFields.

JFormattedTextField textF1;
JFormattedTextField textF2;

       textF1 = new JFormattedTextField(numberFormat);
       textF2     = new JFormattedTextField(numberFormat);

JPanel labelPane = new JPanel(new GridLayout(0,1));
        labelPane.add(textF1)
        labelPane.add(textF2)



        setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));

        add(labelPane, BorderLayout.LINE_START);
        add(fieldPane, BorderLayout.CENTER);
        add(imagePane, BorderLayout.LINE_END);

problem is with fieldPane. It always shrinks. I have tried to set textfield to minimum size, set manually dimensions. Even set prefferd size, setMaximumSize. Not of this works.LabelPane and imagePane work fine.

palyxk
  • 341
  • 2
  • 4
  • 17
  • 2
    1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (Yes.) 3) Use a logical and consistent form of indenting code lines and blocks. The indentation is intended to make the flow of the code easier to follow! 4) Try using [`setColumns(int)`](http://docs.oracle.com/javase/8/docs/api/javax/swing/JTextField.html#setColumns-int-) to suggest a size. – Andrew Thompson Nov 03 '16 at 14:39

1 Answers1

2

Method setColumns(int) worked. Thanks.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
palyxk
  • 341
  • 2
  • 4
  • 17
  • Sometimes the simplest methods (found using a careful inspection of the Java Docs, **including [inherited methods](http://docs.oracle.com/javase/8/docs/api/javax/swing/JFormattedTextField.html#methods.inherited.from.class.javax.swing.JTextField)**) is the best way to go about it. ;) – Andrew Thompson Nov 03 '16 at 15:28