The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

This topic is READ ONLY
import-bot (20211) [Avatar] Offline
#1
[Originally posted by fritb]

I'm having a couple of problems using native fonts with JDK 1.2.2 on Windows
NT.

As shown in the program below, once you set a given native font for a
component, if you then set a new font with the same name and point size, but a
different style, the new style will not be put into effect. This is not the
case for a standard font (serif, sanserif, monospaced, dialog).

The other problem is that without the call to getAvailableFontFamilyNames()
for the local graphics environment, I can't get the right native font even if
I specify it correctly by name. On my system, if I call setFont using a
native font without first calling getAvailableFontFamilyNames(), it will
always use Arial. It appears that getAvailableFontFamilyNames() does some
sort of initialization that allows native fonts to be selected correctly, but
the JDK documentation says nothing about this requirement.

Are these bugs, or am I missing something?


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class FontTest2 extends JFrame
{
static public void main(String[] args)
{
FontTest2 ft = new FontTest2();
ft.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { System.exit(0); } });
ft.getContentPane().setLayout(new GridLayout());

// Without calling this, Arial is always used even when a different native
// font is requested.
//
GraphicsEnvironment.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames();

// Set up a text field using a standard font and plain style.
//
JTextField textfield1 = new JTextField();
ft.getContentPane().add(textfield1);
textfield1.setFont(new Font("serif", Font.PLAIN, 24));
textfield1.setText(textfield1.getFont().getFamily());

// Set up a text field using a native (Windows) font and plain style.
//
JTextField textfield2 = new JTextField();
ft.getContentPane().add(textfield2);
textfield2.setFont(new Font("arial", Font.PLAIN, 24));
textfield2.setText(textfield2.getFont().getFamily());

ft.setSize(400, 100);
ft.setVisible(true);

// Wait a couple of seconds so effect of font change can be observed.
//
try { Thread.sleep(2000); }
catch (InterruptedException iex) {}

// Now try to change style to italic for both text fields; this works for
// the standard font, but not the native font. However, if the point size
// is also changed for the native font, both it and the style change WILL
// take effect.
//
textfield1.setFont(new Font("serif", Font.ITALIC, 24));
textfield2.setFont(new Font("arial", Font.ITALIC, 24));
}
}
import-bot (20211) [Avatar] Offline
#2
Re: Problems with native fonts
[Originally posted by fritb]

I had searched the bug parade and didn't see anything about either problem.
I'll go ahead and post them there and see what Sun has to say.
import-bot (20211) [Avatar] Offline
#3
Re: Problems with native fonts
[Originally posted by matt]

Style changes without proper updating a bug. I'm not sure about
getAvailableFontFamilyNames().. have you checked the JDC bug
database? Both these issues belong there if they aren't already...