0

In a java program, I created a TextArea a MenuBar, But I am unable to change font family of the TextArea

Only

ta.setFont(new Font(Font.SERIF,Font.PLAIN,14));

is working since here I used Font class constants.

But this is not working...

ta.setFont(new Font("Arial",Font.PLAIN,14));

After this statement the font in TextArea is still default. Neither "Comic Sans MS" is working..

Sukhbir
  • 553
  • 8
  • 23
  • 1
    Are you using `SWING` or `AWT` or `JAVAFX` components ? Because in the documentation of Oracle I could't find a method for any of the frameworks where you can use something like this `setFont("Arial",Font.PLAIN,14);` – Kami Jul 30 '15 at 09:28

1 Answers1

1

Try:

textArea.setFont(new Font("Arial", Font.PLAIN, 14));
  • Text is still default – Sukhbir Jul 30 '15 at 11:06
  • Have you copied exactly the code above or have you adapted to your code? For you code, the solution is: `ta.setFont(new Font("Arial", Font.PLAIN, 14));` – p3droonline Jul 30 '15 at 14:04
  • 1
    I have found out from http://stackoverflow.com/questions/6922959/how-to-add-new-fonts-to-itext-using-java `BaseFont base = BaseFont.createFont("c:/windows/fonts/arial.ttf",BaseFont.WINANSI); Font font = new Font(base, 11f, Font.BOLD);` – p3droonline Jul 30 '15 at 14:09
  • But I can't find BaseFont in java doc – Sukhbir Jul 30 '15 at 15:28
  • Forget about BaseFont. I suggest you take look at this site http://docs.oracle.com/javase/7/docs/api/java/awt/Font.html#createFont(int,%20java.io.File). – p3droonline Jul 30 '15 at 19:18