使用 JTextField 列出项目

发布于 2024-12-13 00:02:53 字数 315 浏览 2 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔落墨 2024-12-20 00:02:54

您只需定义一个临时字符串、结果,并将列表中的每个项目的字符串表示形式添加到该变量即可。当您循环完所有内容后,您所需要做的就是textArea.setText(result)

String result = "";    
for(int i = 0; i < list.size(); i++)
{
    result += list.get(i).toString();
}

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 is textArea.setText(result).

String result = "";    
for(int i = 0; i < list.size(); i++)
{
    result += list.get(i).toString();
}

textArea.setText(result);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文