I am trying to create a simple notepad in Java.
This is the code that I think contains the problem:
if(cb.getSelectedItem().equals("Plain")){
MainText.setFont(new Font(getFontName(MainText),
Font.PLAIN,
getFontSize(MainText)));
}
Here are the methods used above:
public int getFontSize(TextArea t){
return t.getFont().getSize();
}
public String getFontName(TextArea t){
return t.getFont().getFontName();
}
public int getFontStyle(TextArea t){
return t.getFont().getStyle();
}
Setting the
Fontthe way you have it is perfectly fine. You can also do it like this:As the
Fontcode is fine, you should ensure that yourcb.getSelecedItemtest is working as expected. Perhaps stepping through or including some debug statements would be a good next step.Also, note that in Java it is convention to begin variable names with lower case letters. Upper is used to start class names.