【问题标题】:Getting a List from a Swing Textbox从 Swing 文本框中获取列表
【发布时间】:2016-10-13 13:35:07
【问题描述】:

我正在尝试使用 Swing GUI 从用户那里获取列表输入。是否可以在文本框中获取列表?例如,用户会写

132、234、76、14、9

我会将其保存到一个数组中以供以后使用。

【问题讨论】:

    标签: java swing list textbox


    【解决方案1】:

    假设你使用的 TextField 有变量名textbox

        String textboxValue = textbox.getText();//where textboxValue would equal to 132, 234, 76, 14, 9
        String [] numbers = textboxValue.split(",");//Stored in this array using regular expression (regex) in java
    
        for (String number : numbers) {
            System.out.println(""+number);
        }
    

    【讨论】:

      【解决方案2】:

      您必须通过Textfield#getText 获得String,然后您可以将String#split 与您想要的分隔符一起使用。请注意,分隔符是RegEx

      【讨论】:

        猜你喜欢
        • 2016-03-10
        • 1970-01-01
        • 1970-01-01
        • 2013-08-10
        • 2011-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-12
        相关资源
        最近更新 更多