Hi, i am trying to do a project using Java language and MySQL.
In my Java interface, there have a JComboBox which will calling MovieName from MySQL database.
After i click on one of the MovieName in JComboBox, the schedule and also the information of the MovieName from the database should be showing in JList. It seen to be success. However, it is not.
The problem is: I cannot remove the data from JList as whole.
For example, In my database, Wall-E has 3 schedule on a choosen day while Transformer2 has only 1 schedule on the same day.
The first time i am choosing Transformer2 in JComboBox, 1 schedule is show in JList(success).
The second time i am choosing Wall-E in JComboBox, 3 schedule is show in JList(success).
For the third time, when i choose Transformer2 again in JComboBox, 3 schedule is show in JList at which only the schedule with index[0] is from Transformer2, the schedule with index[1] and index[2] is the schedule for Wall-E which i cannot remove as the whole.
I have try all kinds of method that i search online, but it still not work to solve my problem.
So can someone give me some hints so that i can solve this problem correctly.
Thanks.
Here is some parts of my coding:
dList = new DefaultListModel();
jlMovieTime = new JList(dList);
jlMovieTime.setFont (new Font ("Times New Roman", Font.BOLD+Font.ITALIC, 18));
jpWest.add(jlMovieTime);
jlMovieTime.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
c.add(jpWest, "West");
private void resetModelData(String[]MovieTime){
if(jlMovieTime.getModel().getSize()==1){
dList.remove(0);
dList.clear();
}
else if(jlMovieTime.getModel().getSize()==2){
dList.remove(0);
dList.remove(1);
dList.clear();
}
else if(jlMovieTime.getModel().getSize()==3){
dList.remove(0);
dList.remove(1);
dList.remove(2);
dList.clear();
}
else{
dList.clear();
dList.removeAllElements();
}
for(int m=0; m<MovieTime.length; m++){
dList.add(m, MovieTime[m]);
}//end for
jlMovieTime.repaint();
jlMovieTime.revalidate();
jlMovieTime.updateUI();
}
public void actionPerformed (ActionEvent e) {
String command = e.getActionCommand();
movieIndex = cbMovieName.getSelectedIndex();
if(command.equals("Get Time")){
DisplayTime();
resetModelData(MovieTime);
}
* DisplayTime() is a method use to call the information of a Movie from MySQL and display the information on JList. This coding works correctly.