我创建了一个JDropDown菜单。我需要在JFrame上其他位置的子菜单,基本上,这是另一个JDropDown菜单。并以类似“否”下拉菜单的条件显示在开始处,但在单击任何下拉选项后,将显示另一个下拉菜单,以及基于主下拉菜单的第二个下拉菜单的选项。
我已经尝试过该代码。单击第一个下拉菜单中的任何选项,就会显示第二个下拉菜单。但是如果我再用cb.setSelectedIndex(1)添加一件事,那将无法工作。
String[] choices = {"Redeem","Prepaid", "FRC","Offices","Individual Bags","Gift Subscription","E-Gift Card","My Account","Wp-Admin","Shipstaion","Any date changes"};
final JComboBox cb = new JComboBox(choices); cb.setBounds(134,200, 170,30);
cb.setSelectedIndex(0);
cb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try {
String[ ] choices1 = {"Redeem Remaining & Redeem Gift Card","Redeem of Tasting Kit Sub","US & NON-US Redeem","Manually Created Vouchers"};
final JComboBox cb1 = new JComboBox(choices1);
cb1.setBounds(100,250, 250,30);
JF.add(cb1);
} catch (Exception e1) { e1.printStackTrace(); }
}
});
预期结果应该是基于主下拉选项显示的第二个下拉选项。