使用 JTextField 列出项目
我对 Java GUI 编程不太熟悉,我想做一些事情,我有一个循环,可以吐出一系列内容,并让 JTextField 按其出现的顺序呈现它。
我只是不知道 JTextField insert() 函数的第二个参数如何工作。现在,当我做类似的事情时:
for(int i = 0; i < list.size(); i++){
textArea.insert(list.get(i), 0);
}
它会做我想要的事情,除了它按倒序列出我放入的所有内容。我希望它以相反的方式显示所有内容。
感谢您的任何建议。
I'm not too familiar with Java GUI programming, and I wanted to do something where I have a loop that spits out a list of stuff and have the JTextField render it in the order it comes out.
I just do not know how the second parameter of the JTextField insert() function works. Right now when I do something like:
for(int i = 0; i < list.size(); i++){
textArea.insert(list.get(i), 0);
}
It does what I want, except it lists everything in backwards order that I put it in. I want it to display everything the other way around.
Thank you for any advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需定义一个临时字符串、
结果
,并将列表中的每个项目的字符串表示形式添加到该变量即可。当您循环完所有内容后,您所需要做的就是textArea.setText(result)
。All you need to define a temporary string,
result
and for every item in the list add the string representation to that variable. When you have looped through everything, all you need to do istextArea.setText(result)
.