-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.3.0
-
generic
-
solaris_2.6
First and foremost, the fonts obtained from from the method
GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(), some works
and some will crash the X-window system. The crash likely occurs for those
fonts that has the postfix "Alt". As demonstrated by the following attached
program. The user will have to enabled either the display and/or the textfield
for the test string to be displayed.
Secondly and not as important is the returned Font[] of this method getAllFonts().
The entry 0 contain a font with no name. Is this right?
---------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class fonts1 extends Frame implements ItemListener {
String []s;
displayCanvas canv = new displayCanvas();
TextField tf = new TextField("Hello", 45);
Checkbox cb1 = new Checkbox("Canvas Enable", false);
Checkbox cb2 = new Checkbox("TextField Enable", false);
Hashtable ht = new Hashtable();
fonts1() {
setLayout(new BorderLayout());
Panel np = new Panel(new GridLayout(2, 1));
add(np, BorderLayout.NORTH);
cb1.setBackground(Color.pink);
cb2.setBackground(Color.pink);
Panel cp = new Panel(new FlowLayout());
cp.add(cb1);
cp.add(canv);
np.add(cp);
cp = new Panel(new FlowLayout());
cp.add(cb2);
cp.add(tf);
np.add(cp);
Panel p = new Panel(new GridLayout(25, 4));
add(p, BorderLayout.CENTER);
CheckboxGroup cbg = new CheckboxGroup();
Checkbox b = new Checkbox("Phony Bologne", true, cbg);
p.add(b);
b.addItemListener(this);
Font []f =
GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
for (int i = 0; i < f.length; ++i) {
f[i] = f[i].deriveFont((float)18.0);
ht.put(f[i].getFontName(), f[i]); // save in the hashtable
b = new Checkbox(f[i].getName(), false, cbg);
p.add(b);
b.addItemListener(this);
}
setSize(800, 800);
setVisible(true);
pack();
validate();
}
public void itemStateChanged(ItemEvent e) {
Checkbox b = (Checkbox) e.getItemSelectable();
String s = b.getLabel();
System.out.println(s);
Font f = (Font) ht.get(s); // retrieve from the hashtable
if (cb1.getState())
canv.redraw(f);
if (cb2.getState()) {
tf.setFont(f);
tf.setText("Hello World in " + s + " " + Font.PLAIN + " " + 16);
tf.repaint();
tf.validate();
}
validate();
}
class displayCanvas extends Canvas {
String name = "Default";
int style = Font.PLAIN;
int size = 24;
Font f = new Font(name, style, size);
displayCanvas() {
setSize(500, 150);
setBackground(new Color(236, 255, 213)); // light blue
}
public displayCanvas(Font f) {
this.f = f;
setBackground(new Color(236, 255, 213)); // light blue
setForeground(new Color(0, 0, 0)); // black
}
public void redraw(Font f) {
this.f = f;
repaint();
}
public void paint(Graphics g) {
System.gc();
g.setFont(f);
g.drawString("Hello there! in " +
f.getName() + "-" +
f.getStyle() + ", size = " +
f.getSize(),
35, 100);
}
}
public static void main(String argv[]) {
fonts1 f = new fonts1();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
}
}
---------------------------------------------------------------------------------
Roger Pham 10/26/99
GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(), some works
and some will crash the X-window system. The crash likely occurs for those
fonts that has the postfix "Alt". As demonstrated by the following attached
program. The user will have to enabled either the display and/or the textfield
for the test string to be displayed.
Secondly and not as important is the returned Font[] of this method getAllFonts().
The entry 0 contain a font with no name. Is this right?
---------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class fonts1 extends Frame implements ItemListener {
String []s;
displayCanvas canv = new displayCanvas();
TextField tf = new TextField("Hello", 45);
Checkbox cb1 = new Checkbox("Canvas Enable", false);
Checkbox cb2 = new Checkbox("TextField Enable", false);
Hashtable ht = new Hashtable();
fonts1() {
setLayout(new BorderLayout());
Panel np = new Panel(new GridLayout(2, 1));
add(np, BorderLayout.NORTH);
cb1.setBackground(Color.pink);
cb2.setBackground(Color.pink);
Panel cp = new Panel(new FlowLayout());
cp.add(cb1);
cp.add(canv);
np.add(cp);
cp = new Panel(new FlowLayout());
cp.add(cb2);
cp.add(tf);
np.add(cp);
Panel p = new Panel(new GridLayout(25, 4));
add(p, BorderLayout.CENTER);
CheckboxGroup cbg = new CheckboxGroup();
Checkbox b = new Checkbox("Phony Bologne", true, cbg);
p.add(b);
b.addItemListener(this);
Font []f =
GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
for (int i = 0; i < f.length; ++i) {
f[i] = f[i].deriveFont((float)18.0);
ht.put(f[i].getFontName(), f[i]); // save in the hashtable
b = new Checkbox(f[i].getName(), false, cbg);
p.add(b);
b.addItemListener(this);
}
setSize(800, 800);
setVisible(true);
pack();
validate();
}
public void itemStateChanged(ItemEvent e) {
Checkbox b = (Checkbox) e.getItemSelectable();
String s = b.getLabel();
System.out.println(s);
Font f = (Font) ht.get(s); // retrieve from the hashtable
if (cb1.getState())
canv.redraw(f);
if (cb2.getState()) {
tf.setFont(f);
tf.setText("Hello World in " + s + " " + Font.PLAIN + " " + 16);
tf.repaint();
tf.validate();
}
validate();
}
class displayCanvas extends Canvas {
String name = "Default";
int style = Font.PLAIN;
int size = 24;
Font f = new Font(name, style, size);
displayCanvas() {
setSize(500, 150);
setBackground(new Color(236, 255, 213)); // light blue
}
public displayCanvas(Font f) {
this.f = f;
setBackground(new Color(236, 255, 213)); // light blue
setForeground(new Color(0, 0, 0)); // black
}
public void redraw(Font f) {
this.f = f;
repaint();
}
public void paint(Graphics g) {
System.gc();
g.setFont(f);
g.drawString("Hello there! in " +
f.getName() + "-" +
f.getStyle() + ", size = " +
f.getSize(),
35, 100);
}
}
public static void main(String argv[]) {
fonts1 f = new fonts1();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
}
}
---------------------------------------------------------------------------------
Roger Pham 10/26/99