1

I am making a program that is supposed to allow you to type in text, and it will that text in every single font on the computer. Here is a screenshot of what happens just as the fonts are loaded: A screenshot Now, I realize that there are a billion other problems besides the automatic resizing of the JTextFields, but I want to focus on one thing at a time. Anyway, whenenver I scroll down in the JScrollPane, here's what happens: A screenshot Could someone please tell me what I have to do with the GridBagConstraints or the JTextFields to fix this problem? Here's a bit of code, hope it helps -

 gbc.insets = new Insets(2, 5, 2, 5);
 gbc.gridx = 0;
 gbc.gridwidth = gbc.gridheight = 1;
 gbc.weightx = gbc.weighty = 1;
 gbc.anchor = GridBagConstraints.LINE_START;
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Daniel Bezden
  • 426
  • 3
  • 8
  • 20

1 Answers1

5

Try adding gbc.fill = GridBagConstraints.HORIZONTAL to encourage the components to use the available horizontal space.

A better solution would be to use a JList.

I would add each Font to a ListModel and using the master text, allow a ListCellRenderer to render it.

But that's me

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • "But that's me" Nay, I think that's a lot of people – ignis Oct 28 '12 at 05:49
  • 1
    See also [this example](http://stackoverflow.com/questions/6965038/getting-fonts-sizes-bold-etc/6965149#6965149) using a combo-box for the font list. It customizes a `DefaultListCellRenderer` into a `FontCellRenderer`. – Andrew Thompson Oct 28 '12 at 06:29