Fonts in java

Hello,
I'm sorry if i post this topic here, but I can't find any solution for my problem. I have develope an application with NetBeans in Windows. I have make a standalone software. Label's font are "Tahoma". Now I wanna modify my application. Now I use NetBeans under Ubuntu. When I click on a label in NetBeans' gui-editor and I choose font, the list of font available are only: Courier, Default, Dialog, DialogInput, Lucida Bright, Lucida Sans, Luxi Mono, Luxi Sans, Luxi Serif, Monospaced, SansSerif and Serif. Tahoma there aren't, but in my Ubuntu Systems fonts are too many more, and Tahoma there are! If I run this application JVM can't visualize text with Tahoma fonts and this text are in other font.
Can anyone help me?
Thanks so much!!!

Check out 2D FAQ:
http://java.sun.com/products/java-media/2D/reference/faqs/index.html#Q_What_font_types_does_Java_2D_s
And Text tutorial:
http://java.sun.com/developer/onlineTraining/Media/2DText/

Similar Messages

  • Deprecation warning for getFontMetrics(java.awt.Font) in java.awt.Toolkit

    Hi all,
    When I use the following code
    JComponent c;
    FontMetrics metrics = getToolkit().getFontMetrics(c.getFont());
    I get this following warning during compilation:-
    warning: getFontMetrics(java.awt.Font) in java.awt.Toolkit has been deprecated
    JDK suggests to use getLineMetrics() of the Font class.
    But there's an issue with that: if I use getLineMetrics(), there is no API method that I can use to get the width of a string as opposed to FontMetrics which provides stringWidth(String str) method for that purpose. In fact all the methods in FontMetrics are not mapped into LineMetrics.
    Could anyone please help or provide me at least some pointers on how to tackle this issue so that I can get rid of the deprecated method along with the existing methods mapped to equivalent APIs? The bottomline is that I should be able to maintain the existing functinality of my application for those part of code that uses getToolkit().getFontMetrics().
    Thank you for your help in advance.
    -Sanjoy Das

    Use Graphics.getFontMetrics(font) instead.
    After creation your frame and calling frame.show();
    You can access it like that
    frame.show();
    frame.getGraphics().getFontMetrics(new Font("Arial",0,10));
    before showing graphics is null.
    Or just create a BufferedImage and ask it for graphics.
    BufferedImage img=new BufferedImage(...);
    img.getGraphics().getFontMetrics(font);
    regards
    Stas

  • True Type Fonts in Java

    Hi all
    I searched through the forum and found some threads with the same problem but never a solution attached so here is my question:
    I'm currently trying to use a True Type Font in Java. I installed the font under windows and it works fine in e.g. Word, but when I try to use it in Java all I can see are "rectangles". I'm not sure if the problem lies in the font itself or if it is a problem of Java. The fonts are named "Fughetta" and "Toccata" and can be found here: http://www.efn.org/~bch/aboutfonts.html. He is a code snippet I'm using to test the font:
    public void setFonts(Graphics g)
            if (f != null) {
                return;
            f = new Font("Fughetta", Font.TRUETYPE_FONT, 26);
            System.out.println(f);
        public void paintComponent(Graphics g)
            super.paintComponent(g);
            setFonts(g);
            String s1 = "1234567890��!\"�$%&/(()=?`";
            String s2 = "qwertzuiop�+asdfghjkl��#yxcvbnm,.-<";
            String s3 = "QWERTZUIOP�*ASDFGHJKL��'YXCVBNM;:_>";
            String s4 = "1��{[]\\}@�~�|";
            g.setFont(f);
            g.drawString(s1, 10, 30);
            g.drawString(s2, 10, 70);
            g.drawString(s3, 10, 110);
            g.drawString(s4, 10, 150);
        }All help is appreciated ;)
    - marc

    Hy, Thanks for your sollution, but now I can't use this kind of approach.
    I need to show a Bar Code Font inside a JTable cell, so I created my CellRenderer, in which I tried to change the font to my "Code EAN13" True Type font.
    public Component getTableCellRendererComponent(JTable table,
                Object value, boolean isSelected, boolean hasFocus, int row, int column)  {
                 Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                 if (column == CollectInfoTableModel.CODBAREPRODUS_INDEX ) {
                         Font barCodeFont = new Font("Arial", Font.BOLD, 36);
                         c.setFont(barCodeFont);                 
    }This doesn't work, it just prints some strange characters.
    I tried your sollution, but when I make :
    Graphics2D g2D= (Graphics)c.getGraphics();i keep getting g2D = null.
    What can I do ?
    Is there a way to obtai a valid Grapics object on which to draw the glyphVector on ?

  • Fonts in java apps for win and linux

    Hi everyone.
    i need to build an application mult-plataform, to run in windows and linux...
    but i don�t know waht font i must use...the default font that java takes doesn�t exist in linux (dialog)...
    waht font should i use in my app??
    thanx

    For going multi-platform it is easiest to stick to the logical fonts: Fonts named "Serif", "SansSerif", "Monospaced", "Dialog", and "DialogInput".
    These fonts are guaranteed to exist on any platform, although their implementations may be different. If you use others then you'll have to figure out how to deal with cross platform issues.
    Jeff

  • Printer Built-in fonts in java

    Hello,
    I'm using Imaje 2000 Series Printer, when opening a new microsoft word document I can see some built in fonts specific to that printer like Imaje Arial, Imaje Times New Roman B, etc... I found out when printing with one of these fonts, the printing process is very fast. what happens is that I can see those fonts with name Imaje in MS word with printer icon attached to them, but in java i cant see them, and to check all fonts in java i used the below code :
    Font[] f = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    for (int i=0; i<f.length; i++) {
    System.out.println(f.getFontName());
    if i try to set the font to Imaje Arial, java will neglect that font and print on the default I guess. Is there a way to use the printer built in fonts from within my java application

    well, i cant find the font in windows fonts
    directory, but when I open MS wrod i can find the
    font (for example: Imaje Arial) in the fonts list and
    has an icon of printer which means its not a true
    type font. and please note that this font Imaje Arial
    did not appear in MS word before installing the
    printer driver.Well, if it's not installed and you can't find the file, how do you expect Java to do it?

  • Displaying Windows True Type fonts using Java 1.1.x

    Can anyone shed some light on why I cant just use the name of the fon't I want to display? Here is the code I'm using:
    Font font1 = new Font(sFontName, iStyle, iSize);
    this.setFont(font1);
    sFontName is the name of the font, and it works with the font names that are garaunteed by Java (i.e. Dialog, DialogInput, Monospaced, Serif, SansSerif, or Symbol), but if I try to use a true type font name such as "Tahoma" it just loads the default font instead. Is there a different method required to load system dependant fonts?
    Any ideas would be greatly appreciated. Thanks.

    If your font is properly installed (i.e. in the fonts folder and you've performed a restart) then it should work. I have code in the splash screen for an open source project like this:
    subTitleLbl.setFont (new java.awt.Font ("Lucida Blackletter", 0, 18));Which works if the font is properly installed. Otherwise, it simply grabs the system font, as you indicated.
    I've done some searching, and haven't found a way to load a font into java. Java won't do it because it's not platform independent.
    Fortunately, this code works even if the font is not present--it just won't have the font you want.

  • Adding fonts to java

    Hi all,
    was wondering if it is possible to add new fonts to java (1.4). currently on my system, there is 32 fonts, but was wondering if it was possible to get access to all fonts on the system? or how to add them to the jvm?
    thanks,
    Justin

    I think this should work on any platform:
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font allfonts[] = ge.getAllFonts();This will give you a one point font
    and then Font.deriveFont(float); should get you the proper size.

  • Fonts in Windows and Fonts in Java

    Hello,
    Say I have in my app:
    String string = "\\u09A1";
    I want to display this in my app. I can call:
    GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    I can then iterate through these and find out which ones can display this unicode character using,
    font.canDisplayUpTo(string);
    My question is, are these the fonts that Java can display (from charsets.jar) or the ones installed in Windows?
    I would like to be able to get lists for both of these.
    Any ideas?
    Cheers,
    Jim

    Thank you. I did read that. I was not talking about drawing text in 'Hello World' alike applets/programs.
    I should give an example:
    I would like to print 'H' in Tahoma, 72, Bold (Windows format) at (100, 200).
    Font sizes:
    In Windows font size is 72 pixels.
    In Java this is equal to 96 points (72 px * 96 (scr resolution for Toolkit) / 72 (pixels per point).
    Real height in Windows and Java will be 64 px.
    That's fine. For some fonts this does not work.
    Positioning. See example above.
    According to the article you refer to in java we should use y-coordinate 200 + 72 (font size) = 272.
    In fact we have :
    Java text 14 pixels below than expected.
    Similar things happen to other parameters Weight, Styles, etc.
    I do use AttributedString and TextAttribute classes to render text
    Thanks in advance.
    Alex

  • Missing fonts in Java

    Reformated my XP SP3 computer and loaded Firefox 13.0.1 and Java from Oracle.
    When I open any pages that have javascripted close X's on them I receive a square box with 27 over 16 in it instead of the X.
    On one site the code reads:
    font-family: "Helvetica Neue",Helvetica,Arial,Verdana,sans-serif;
    <a href="javascript:return void(0);">✖</a>
    (Not sure if that will show up at your end as a little box - or - a little box with the 27 and 16 in it).
    I checked http://browserspy.dk and got a list of 45 fonts on Fonts Information - Detected via Flash (http://browserspy.dk/fonts-flash.php) but
    only 36 on Fonts Information - Detected via Java (http://browserspy.dk/fonts-java.php)
    Helvetica is missing from both lists.
    These fonts are showing up on the Java page but not the Flash page.
    Dialog
    DialogInput
    Lucida Sans
    Monospaced
    SansSerif
    Serif
    These fonts are showing up on the Flash page but not the Java page.
    Arial Baltic
    Arial CE
    Arial CYR
    Arial Greek
    Arial TUR
    Courier New Baltic
    Courier New CE
    Courier New CYR
    Courier New Greek
    Courier New TUR
    Times New Roman Baltic
    Times New Roman CE
    Times New Roman CYR
    Times New Roman Greek
    Times New Roman TUR
    Really not sure what to do about this.
    Is there someway I can get Flash/Java to recognise these fonts?
    Thank You

    That is an Unicode symbol &amp;#x2716;
    If you see the hex code instead of the character then Firefox wasn't able to find a (dingbat) font that handles this character.
    *http://www.alanwood.net/unicode/dingbats.html

  • Fonts in Java and Windows, TextOut vs drawString

    Hi everyone,
    I need to render documents (standard format, that uses LOGFONT Windows struct.) in my Java App exactly like my Windows App. shows.
    There are several issues:
    1. Font sizes. (I almost resolved the problem)
    2. Font styles. I noted that Java does not work properly with native fonts. Sometimes, it ignores font styles. I did apply workarounds recommended in the bug tracking db. It helps only for some fonts, not for all.
    3. Mapping character sets.
    4. Positioning. TextOut uses left topmost corner. drawString uses the baseline. Also, Windows displays some extra space at the top. I could not calculate its size from FontMetrics. Also, there are issues horizontal positioning when I use Italic.
    5. StrikeOut and Underline - also different look.
    6. Also, I noted when I use some rare font Java draws some garbage along with text.
    If anywone was working on that, your help would be really appreciated.
    Thanks in advance,
    Alex

    Thank you. I did read that. I was not talking about drawing text in 'Hello World' alike applets/programs.
    I should give an example:
    I would like to print 'H' in Tahoma, 72, Bold (Windows format) at (100, 200).
    Font sizes:
    In Windows font size is 72 pixels.
    In Java this is equal to 96 points (72 px * 96 (scr resolution for Toolkit) / 72 (pixels per point).
    Real height in Windows and Java will be 64 px.
    That's fine. For some fonts this does not work.
    Positioning. See example above.
    According to the article you refer to in java we should use y-coordinate 200 + 72 (font size) = 272.
    In fact we have :
    Java text 14 pixels below than expected.
    Similar things happen to other parameters Weight, Styles, etc.
    I do use AttributedString and TextAttribute classes to render text
    Thanks in advance.
    Alex

  • Please,help with fonts in Java

    I have one problem, I would like, that I could see and Faroese islands fonts and cirilica (Russian fonts) at the same time in TextBox, List and TextArea (awt). How it is possible to do?
    Please write me to email: [email protected] or here in forum.

    Each of those objects can only use one font at a time. If you want an object that can use many fonts, then JTextPane is such an object. However it is a Swing object, so it requires Java 2, and it is quite complicated to use. If you are limited to AWT, your other possibility is to draw the text on a Canvas using the various fonts.

  • Using Type 1 fonts in Java 1.5

    I'm trying to use the Font.createFont() method to instantiate a Type 1 font. The second parameter to the createFont() method asks for a filename...but what kind of Type 1 file is needed? I've tried .pfa, .pfb, and .pfm files, and Java doesn't recognize any of them as proper Type 1 files.
    Can anyone who knows something about Type 1 fonts help? (I only know just enough to be completely confused about the different Type 1 filetypes.)
    Thanks.

    The exception I'm getting looks like this:
    java.awt.FontFormatException: Unrecognised Font Format
         at sun.font.FontManager.createFont2D(FontManager.java:1520)
         at java.awt.Font.<init>(Font.java:438)
         at java.awt.Font.createFont(Font.java:745)

  • Ugly, distorted fonts in Java apps.

    So I'm getting weird-looking fonts in all Java applications such as MultiBit.
    For example:
    How can I fix this?

    Does this help?: https://wiki.archlinux.org/index.php/Ja … i-aliasing

  • Unicode fonts in java

    Greetings. I have two TrueType fonts I'm trying to display in my java application. Both fonts have been "installed" on my Windows machine, one of them works just find (I can see Graphics.drawString("A", ...) and the corresponding A symbol is displayed. However, when using the other font, I get the missing character symbol, unless I use a unicode escape sequence, e.g. "\uf040". Both fonts, incidentally are military-symbol fonts, and they are very similar in nature. Why does one font require I use the escape sequence, while one does not, and is there anyway I can configure the JRE so that I can avoid having to use the escape code?

    When I open the font that isn't working directly (using a font viewer), the same letter "A" that is mapped to, say, "Times New Roman" is also mapped to the letter "A" for this font (in other words, it's not using characters outside of my keyboard capability). To put this another way, MS Word displays the characters just fine when I type them in with my keyboard-- Java 2D does not.
    The reason I don't want to use the Unicode escapes is because I can't seem to figure out an easy way to display all the characters between, say, 40 and 200 in a loop-- in other words, how would I go about constructing the unicode escape string while in a loop? you can't simply say "/u" + loopVariable because it's not a string literal.

  • Ugly fonts in java under linux

    I'm using JRE 1.5.0_03-fcs under Fedora Core 3. Some of the applications I run have really bad fonts, which look pixellated, and are difficult to read. When I asked on the Fedora mailing list, someone said that jre uses its own font rendering engine, instead of the one used by X window, and so none of my installed fonts will be recognised and used by jre.
    So, my question is: how do I improve this situation? What can I do to make jre recognise the Microsoft and other fonts I have installed, and how do I make a certain application use a font of my choice, instead of the ugly default?
    Anand

    Hi,
    Ok, I tried the setting you suggested, ie. -Dswing.aatext=true, but it made no difference. What does that option do?
    I have created a screenshot of the application, if anyone is interested in seeing it. Perhaps it will explain better what the problem is.
    http://anand.org/java-app.png

Maybe you are looking for