Add components directly to the form.

frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridBagLayout()); frame.add(scrollPane, new GridBagConstraints(0,0,1,3,5.0,5.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0,0)); frame.add(replaceArea, new GridBagConstraints(1,0,1,1,1.0,1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0,0)); frame.add(ignoredReplaceArea, new GridBagConstraints(1,1,1,1,1.0,1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0,0)); frame.add(countLetter, new GridBagConstraints(1,2,1,1,1.0,0.2, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0,0)); frame.add(okButton, new GridBagConstraints(0,3,2,1,0.2,1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0,0,0,0), 0,0)); 

If you start writing, the JTextArea is compressed and stretched (Moreover, with an even number of characters it expands, with an odd number it compresses, if you enter three characters, it will be like in the first picture, only along the width of these 3 characters)

Single character Two Three LOT

How to fix the grid?

    0