Petites casquettes en Java Swing?


Existe-t-il un moyen dans Java Swing d'afficher le texte en petites majuscules (petites capitales)? http://en.wikipedia.org/wiki/Small_caps

J'ai chargé une police personnalisée qui prend en charge les petites majuscules via la police.createFont(). Le texte doit être rendu d'une manière ou d'une autre en petites majuscules. Est-ce possible dans JLabel, JTextPane ou un autre composant?

Author: Christian Beil, 2012-02-21

1 answers

Vous pouvez essayer cela, cela fonctionne : (J'obtiens la police ici pour le test: http://www.fonts101.com/fonts/view/Uncategorized/28374/Tahoma_Small_Cap.aspx )

String labelText ="Dfd";
JLabel lbl = new JLabel(labelText);
Font g=null;
Font g2=null;
try {
        InputStream myStream = new BufferedInputStream(new FileInputStream("/home/alain/Bureau/tahomscb/tahomscb.ttf"));
        g = Font.createFont(Font.TRUETYPE_FONT, myStream);
        g2 = g.deriveFont(Font.PLAIN, 24);
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println("font not loaded.");
    }
    lbl.setFont(g2);
    this.add(lbl);  //this is the parent component
 1
Author: alain.janinm, 2012-02-21 11:54:13