需要帮助在 JFrame 中排列 JTextField
我正在用java制作一个数独程序来学习一些算法,所以我希望用户能够输入一个未解决的数独谜题。到目前为止,我创建了 81 (9x9) 个框:
JTextField input[] = new JTextField[80];
for(int i = 0; i <= 79; i++)
{
input[i] = new JTextField();
input[i].setPreferredSize(new Dimension(30,30));
f.getContentPane().add(input[i]);
}
当我运行这个程序时,我得到的只是一个输入字段。我知道所有文本字段都已初始化、创建并添加到 jframe 中。我知道你必须搞乱布局,但我不知道该怎么做。任何帮助都是适当的。
I'm making a Sudoku program in java to learn some algorithms so I want the user to be able to input an unsolved Sudoku puzzle. Here is what I have so far that creates 81 (9x9) boxes:
JTextField input[] = new JTextField[80];
for(int i = 0; i <= 79; i++)
{
input[i] = new JTextField();
input[i].setPreferredSize(new Dimension(30,30));
f.getContentPane().add(input[i]);
}
When I run this program though all I get is just one input field. I know that all the text fields and initialized, created and added to the jframe. I know you have to mess this the layout but I'm not sure how to do that. Any help is appropriated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
JPanel
与网格布局
。另外:
这是 80 个(不是 81 个)文本字段。
更新:(示例代码)
Use a
JPanel
withGridLayout
.Also:
That's 80 (not 81) text fields.
Update: (sample code)
如果您不确定如何使用不同的
Layout
,可以使用 有关 Oracle 文档的精彩教程。如果您想温习组件本身,您还可以查看教程 关于他们。 :)ps: 可能是我太困了,但看起来你已经创建了 80 个文本字段而不是 81 个。
If you are unsure about how to use different
Layout
s there is a great tutorial on Oracle documents. If you want to brush up on the components themselves you could also check out the tutorial on them. :)ps: It might be me being too sleepy but it would appear that you have created 80 text fields not 81.