What I tried is to select an item from a JList
, click a JButton
(optionally also click a JRadioButton
), and then the value of selected item will be added to another JList
.
The problem is that after I clicked the JButton
or JRadioButton
, the item in original JList
was deselected, and what was added to the destination JList
was "null".
first JLists. The items are specified by the selection from a JCombobox, and generate the values from an ArrayList in another class.
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
ChannelList cl = new ChannelList();
cl.createList();
//determine JList by JCombobox selecton
String genre = (String)c.getSelectedItem();
switch(genre){
case "Please Select Genre of Channel":
vt1.clear();
lchannels.setListData(vt1);
break;
case "All Genres":
vt1.clear();
for(int i =0; i < cl.chList.length; i++){
char chGenre = cl.chList[i].getChGenre();
vt1.add(cl.chList[i].getChTitle());
lchannels.setListData(vt1);
}
break;
case "Entertainment":
vt1.clear();
for(int i =0; i < cl.chList.length; i++){
char chGenre = cl.chList[i].getChGenre();
if(chGenre == 'e'){
vt1.add(cl.chList[i].getChTitle());
lchannels.setListData(vt1);
}
}
break;
case "Movie":
vt1.clear();
for(int i =0; i < cl.chList.length; i++){
char chGenre = cl.chList[i].getChGenre();
if(chGenre == 'm'){
vt1.add(cl.chList[i].getChTitle());
lchannels.setListData(vt1);
}
}
break;
case "News/Business":
vt1.clear();
for(int i =0; i < cl.chList.length; i++){
char chGenre = cl.chList[i].getChGenre();
if(chGenre == 'n'){
vt1.add(cl.chList[i].getChTitle());
lchannels.setListData(vt1);
}
}
break;
case "Sci-Fi":
vt1.clear();
for(int i =0; i < cl.chList.length; i++){
char chGenre = cl.chList[i].getChGenre();
if(chGenre == 's'){
vt1.add(cl.chList[i].getChTitle());
lchannels.setListData(vt1);
}
}
break;
case "Sports":
vt1.clear();
for(int i =0; i < cl.chList.length; i++){
char chGenre = cl.chList[i].getChGenre();
if(chGenre == 't'){
vt1.add(cl.chList[i].getChTitle());
lchannels.setListData(vt1);
}
}
break;
}
}