I am trying to change font of my JTextField by using a JComboBox. The problem is when I try to run the program it works fine but now when I try to change font in the program I get tons of errors. Here is the code:
JTextField myJTextField = new JTextField ("This text will be changed!", 20);
myJTextField.setEditable(false);
add(myJTextField);
Font font = new Font ("Serif", Font.PLAIN, 14);
Font font1 = new Font ("Serif", Font.BOLD, 14);
Font font2 = new Font ("Serif", Font.ITALIC, 14);
Font myFonts [] = {font ,font1, font2};
myBox1 = new JComboBox (myFonts);
myBox1.addItemListener (new ItemListener () {
public void itemStateChanged (ItemEvent e) {
Font myFonts [] = {font ,font1, font2};
int array [] = {0,1,2};
if (e.getStateChange() == ItemEvent.SELECTED)
myFonts [0] = new Font ("Serif", Font.PLAIN, 14);
else if (e.getStateChange() == ItemEvent.SELECTED)
myFonts [1] = new Font ("Serif", Font.BOLD, 14);
else if (e.getStateChange() == ItemEvent.SELECTED)
myFonts [2] = new Font ("Serif", Font.ITALIC, 14);
myJTextField.setFont(myFonts[array.length]);
}
}); add(myBox1);
Any help will be really appreciated.