Hello,
In JDK1.5.0 there is a static method in Font class having syntax
Font.createFont(int fontFormat, File fontFile).
This let you create a font using the supplied font file.
Thus it is not necessary whether a particular font is installed on the
machine, we can use font created by this method(?).
The method available previously (in 1.3) has the syntax:
Font.createFont(int fontFormat, InputStream fontStream).
Can we use the functionality of JDK 1.5 in JDK 1.3?
i.e Can we get the InputStream from the TTF file and pass it to the
function to work it like the function available in 1.5 and create a new
Font?
If it is possible, how to do it?
Please help me ASAP.
-Sameer
Thomas Weidenfeller - 09 Mar 2005 10:42 GMT
> Can we use the functionality of JDK 1.5 in JDK 1.3?
> i.e Can we get the InputStream from the TTF file and pass it to the
> function to work it like the function available in 1.5 and create a new
> Font?
Yes. Why didn't you just try it?
> Please help me ASAP.
ASAP? But you couldn't be bothered to write ten lines of code to try it?
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
Sameer - 12 Mar 2005 10:01 GMT
Dear Sir,
I created the font using the method createFont using JDK1.3 and apply
it to a JTextField, but the text displayed is toooo small. Why is it
so? The method font.deriveFont(int) is used and given a big value...
still the text was not displaying.
What may be the problem?
Sameer - 09 Mar 2005 14:08 GMT
Thank you very much for this 'Brain Washing'. I will definately try to
write the code for the same. But I am not confident whether it will
work or not so I want assistance from expert peoples like you and I
just tried whether anybody is kind enough to give me lines for the
same.
-Sameer
Viator - 09 Mar 2005 18:13 GMT
Here are the lines!
try{
Font font=Font.createFont(yourFormat,new
FileInputStream(yourFontFile));
}catch(Exception e){
playWith(e);
}//end try catch
Sameer - 10 Mar 2005 13:54 GMT
Here is the code:
------------------------------
import java.io.*;
import javax.swing.*;
import java.awt.*;
//using JDK 1.3
public class FontTest {
public static void main(String args[]) {
JFrame app= new JFrame("Font Test");
JLabel jl= new JLabel("Hello World");
app.setVisible(true);
app.setSize(400,400);
app.getContentPane().add(jl);
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Font f=null;
try {
//A fontfile for the regional language Marathi(Devnagari)
in India
FileInputStream fis= new
FileInputStream("c:\\winnt\\fonts\\krdev050.ttf");
f= Font.createFont(Font.TRUETYPE_FONT,fis);
} catch (FontFormatException ffe) {
System.out.println(ffe);
} catch (IOException ioe) {
System.out.println(ioe);
}
jl.setFont(f.deriveFont(Font.BOLD,150));
// You will see something in the language Marathi in the frame
}
}