-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
x86
-
windows_nt
Name: krT82822 Date: 04/29/99
Write a simple Java 2 app that makes a call to
'GraphicsEnvironment.getAllFontFamilyNames' and put the
resulting list of names into a JList. Add a JButton to the
display that when pressed will result in another call to
'getAllFontFamilyNames' and repopulate the displayed list.
Now, run the program and after the initial list of fonts are
displayed, manually copy some additional fonts into the WinNT
'fonts' directory.
Press the JButton to reload the list of available fonts and
the newly added fonts will not appear in the list.
If the API is spec'd as "returns the list of available system
fonts", then one would assume that any additional added fonts
after a Java app was running should have access to a newly
installed font.
If I perform the same steps, except using MS Word for example,
the newly installed fonts show up in the font drop-down list
without having to restart the application. However, in my test
java test app, the app needs to be restarted in order to pickup
any new fonts.
What I would really like is an API that can be used to install
a series of bytes that contains a font. I'd like to be able
to install fonts "on the fly" from within my Java code.
Anyway, below is a small program demonstrating my problem.
One additional note: If a font is removed from the system
while this app is running and the "reload fonts" button is
pressed, the app terminate with the following assertion:
Assertion failed: fLength > 0, file ..\..\..\..\src\share\native\sun\awt\font\fontmanager\fontobjects\fontObject.cpp, line 178
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import java.awt.Font;
import java.awt.BorderLayout;
import java.awt.GraphicsEnvironment;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class J2FontTest {
protected JList fontList = null;
public static void main( String args[]) {
new J2FontTest();
}
public J2FontTest() {
JFrame jFrame = new JFrame( "J2FontTest");
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
this.fontList = new JList( ge.getAvailableFontFamilyNames());
JScrollPane jScrollPane = new JScrollPane( this.fontList);
Container cont = jFrame.getContentPane();
cont.setLayout( new BorderLayout());
cont.add( "Center", jScrollPane);
JButton jButton = new JButton( "Exit");
cont.add( "South", jButton);
jButton.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent a_evt) {
System.exit( 0);
}
});
JButton reload = new JButton( "Reload Fonts");
cont.add( "North", reload);
reload.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent a_evt) {
GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
System.out.println( "J2FontTest.actionPerformed: loading new fonts.");
String[] fonts = gEnv.getAvailableFontFamilyNames();
for( int i = 0; i < fonts.length; ++i) {
System.out.println( fonts[i]);
}
J2FontTest.this.fontList.setListData( fonts);
}
});
jFrame.setBounds( 200, 200, 400, 400);
jFrame.setVisible( true);
}
}
(Review ID: 55017)
======================================================================
- duplicates
-
JDK-4229399 API change required to register font dynamically by Apps
-
- Resolved
-