I had problems with changing the font in a Jtextarea, I have 2 views(WidowsP
,TypeJava
), 2 controllers(Controler
, Controler2
) and one model. In this case my problem is in the jtextarea when I change the font the component sends an error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
In my principal view windowP
I have the next components:
Jtextarea = areatexto;
JmenuItem = Jopcions;
My code for the model is:
public void fueltypes(JComboBox numbers,String[] Fonts, JComboBox list){
for(int i =10;i<=30;i++){
numbers.addItem(i);
}
for(String font : Fonts){
list.addItem(font);
}
}
public void changuefont(JTextArea area,String Fonts, int Size ){
Font f = new Font(Fonts,Font.PLAIN,Size);
area.setFont(f);
}
On the controller2 I have this code because in the form I only have 3 items jcombobox1 = The names fonts,jcombobox2 = Size and the only button part I'm changing the code is:
private TypeJava type;
private Window view;
private Modelo model;
private String Fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
public controlador2(TypeJava b,Modelo m){
this.type = b;
this.model = m;
this.type.JMod.addActionListener(this);
this.type.jComboBox1.addActionListener(this);
model.fueltypes(type.jComboBox2,Fonts,type.jComboBox1);
}
@Override
public void actionPerformed(ActionEvent e) {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
if(e.getSource()== this.type.JMod){
model.changuefont(view.areaTexto,
type.jComboBox1.getSelectedItem().toString(),
Integer.parseInt(type.jComboBox2.getSelectedItem().toString()));
}
}