【发布时间】:2019-08-27 09:09:28
【问题描述】:
我是 Java 新手,找不到任何我能够理解的问题的答案。 我想在我的 ComboBox 中选择一个值来更改文本字段中显示的文本。
例如,如果用户在组合框中选择了一位艺术家,则该艺术家的专辑将显示在文本字段中。
感谢任何帮助。谢谢!
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
String a = (String)jComboBox1.getSelectedItem();
int artists = 0;
switch (artists){
case 0: jTextField1.setText("Take Care, Nothing Was The Same, Views, More Life, Scorpion");
break;
case 1: jTextField1.setText("Stoney, Beerbongs & Bentleys");
break;
case 2: jTextField1.setText("One Love, Listen, Nothing But the Beat");
break;
case 3: jTextField1.setText("Ready for the Weekend, 18 Months, Motion");
break;
case 4: jTextField1.setText("Cole World: The Sideline Story, 2014 Forest Hills Drive, 4 Your Eyez Only");
break;
case 5: jTextField1.setText("My Beautiful Dark Twisted Fantasy, Yeezus, The Life of Pablo, ye");
break;
case 6: jTextField1.setText("Parachutes, a Rush of Blood to the Head, X&Y, Viva La Vida, Mylo Xyloto");
}
}
【问题讨论】:
-
您使用的是哪个 GUI 框架? JavaFX、Swing、AWT,还有什么?
-
@eera-l 我觉得
jCombobox说得够多了 -
@MarkJeronimus 起初他发布了没有代码的问题,这就是问这个问题的原因,我什至在我的回答中提到了这一点。