I am correcting Font display in one of our old java Swing application. Which changed after using "-Dfile.encoding=UTF-8" option at run time.
FontClass.jar is my sample jar file.
option 1:
javaw -Xmx256M -jar -Dfile.encoding=UTF-8 "FontClass.jar"
option 2:
javaw -Xmx256M -jar "FontClass.jar"
With option 1: I get Monospaced display
With option 2: I get non Monospaced display.
Limitation:
i) -Dfile.encoding=UTF-8 This option we have added to have all our streams to support UTF-8 support. Insteading of modifing each streams manually.
ii) We are using java swing frame work and in many placeses. We are uisng default Font. Changing all this is lot of work.
So now my question is there is any command line option by using which I can get Monospace display with option 1:
Below is the sample code:
class Show extends Frame {
FontMetrics fontM;
String outString;
Show(String target, String title, Font font) {
setTitle(title);
outString = target;
fontM = getFontMetrics(font);
setFont(font);
int size = 0;
for (int i = 0; i < outString.length(); i++) {
size += fontM.charWidth(outString.charAt(i));
}
size += 24;
setSize(size, fontM.getHeight() + 60);
setLocation(getSize().width / 2, getSize().height / 2);
setVisible(true);
}
public void paint(Graphics g) {
Insets insets = getInsets();
int x = insets.left;
int y = insets.top;
g.drawString(outString, x + 6, y + fontM.getAscent() + 14);
}
}
public class Fontclass {
public static void main(String[] args) {
String jaString = new String("\u65e5\u672c\u8a9e\u6587\u5b57\u5217");
String inputString = "\niiii\naaaaiiii";
String displayString = jaString + " " + inputString;
Font font;
font = new Font("Courier",3, 24);
new Show(displayString, "Demo",font);
}
}