【问题标题】:How to retrieve data from JComboBox and store it in JTextFields?如何从 JComboBox 中检索数据并将其存储在 JTextFields 中?
【发布时间】:2011-02-28 21:38:12
【问题描述】:

我有一个 JComboBox。我想从中检索数据。我知道我使用 getSelectedItem() 方法。但是一旦我得到它,我希望它以某种方式将其转换为字符串..或者最终将其显示在 JTextField 上。

 String[] fluids = { "      ", "string 1", "String 2"}; 
 fluidsList = new JComboBox(fluids);

【问题讨论】:

    标签: java swing jcombobox jtextfield


    【解决方案1】:

    假设 jTextField1 是你的 JTextField 并且流体列表是你的 JComboBox,你必须有这样的东西

    jTextField1.setText(fluidsList.getSelectedItem() == null ? "" : fluidsList.getSelectedItem().toString() );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多