JtextField未显示全文

问题描述 投票:0回答:1

我有一个代码,通过按下按钮生成标签...就像你键入一些随机单词然后它生成一个标签列表,这里是代码

JButton tagGen = new JButton("GENERATE");
        tagGen.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String copyTag;
                String title = textField.getText();
                String[] keywords = {"Google", "Yahoo", "Bing", "DuckDuckGo"};

            for(int i=0; i<keywords.length; i++) {
                copyTag = (title.replaceAll("Search Engine|search |is |Is","") 
                    + keywords[i]+", ");
                textTag.setText(copyTag);
            }
        }

所以问题是我没有得到像这样的完整标签......

随机文本Google,随机文本Yahoo,随机文本Bing,随机文本DuckDuckGo,

而是获得唯一的最后一个标签......

随机文字DuckDuckGo,

我做错了什么?我正在使用setText方法,但它仍然没有打印全文

我试图搜索此问题的修复程序,但找不到任何解决方案

swing jtextfield
1个回答
0
投票

不要使用JextField。

而是在你的循环中使用JTextArea你可以使用:

//textTag.setText(copyTag);
textArea.append(copyTag);
© www.soinside.com 2019 - 2024. All rights reserved.