repainting
I have some code which paints a guitar fretboard onto the screen and then the notes inside thier frets. All these are jpg images which are set using the setIcon method of JLabel. This has been working fine.
I now have a JComboBox which has different tuning notes for the guitar which is attached to an actionListener that changes the tuning, here it should repaint the screen to show the adapted note sequence but I'm having a problem repainting the screen, I'm not using any layout manager here, here's the code segments:
/*Method for drawing the Note images onto the screen*/
publicvoid paintTuningNotes(){
Iterator iter=fretboardMap.iterator();
int stringCount=0;
while(iter.hasNext()){
GuitarString guitarString=(GuitarString)iter.next();
int i=0;
Iterator stringIter=(guitarString.getStringNotes()).iterator();
while(stringIter.hasNext() && i < 12){
ImageIcon note=new ImageIcon();
Note theNote=(Note)stringIter.next();
note=createImageIcon(theNote.getImage());
JLabel noteLabel=new JLabel();
noteLabel.setIcon(note);
fretboardPanel.add(noteLabel);
int offset=((104-((i+2)*3))/2)+(10-(i*2)+(i/2));
System.out.println(offset);
int fretwidth=104-(i*3);
int x=((i+1)*(fretwidth)+50)-offset;
int y=(stringCount*21)+40;
noteLabel.setBounds(x,y,21,21);
i++;
}
stringCount++;
}
}
/*Listener attached to the ComboBox*/
publicclass TuningListenerimplements ActionListener{
publicvoid actionPerformed(ActionEvent e){
Tuning selectedTuning=(Tuning)tunings.get(tuning.getSelectedIndex());
System.out.println(selectedTuning.getTuningName());
fbl.setTuning(selectedTuning);
fretboardPanel.invalidate();
fretboardPanel.repaint();
}
}
/*Overridden paint method (Not too sure on this!)*/
publicvoid paint(Graphics g){
super.paint(g);
paintTuningNotes();
}
I appreciate any help. Cheers
Craig

