JTextFields automatically resizing

谁说胖子不能爱 提交于 2019-12-11 10:07:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!