Look at this code, how to manage the font size on a particular platform(pretty simple)
import java.awt.*;
import javax.swing.*;
public class TextSize extends JPanel {
public void paint(Graphics g) {
Font font = new Font("Arial", Font.PLAIN, 30);
g.setFont(font);
g.drawString("Hello World", 25, 100);
Toolkit tk = Toolkit.getDefaultToolkit ();
int nativeResolution = tk.getScreenResolution();
final double javaResolution = 72.0; // java default is 72 dpi
Font font_new = new Font("Arial", Font.PLAIN, (int)Math.round(30.0*nativeResolution/javaResolution));
g.setFont(font_new);
g.drawString("Hello World", 25, 150);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
TextSize tx = new TextSize();
frame.add(tx);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.setVisible(true);
}
}
One can see the difference of Java and Native font size difference. The first "Hello World" is normal java code. Second " Hello World" is modified java code and third one is Native "Hello World". The staircase problem is also visible in Java Font, for removing that we can set ANTIALIAS_ON :-)
3 comments:
Interesting Sir.
thanks.
It's very easy to understand. :-)
sir,
can u please tell a way to invoke native setting box for managing fonts and other system utilities??
Post a Comment