问题
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:
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: 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;
回答1:
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
来源:https://stackoverflow.com/questions/13106591/jtextfields-automatically-resizing