Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4190792

Label.setFont fails on non-system fonts

XMLWordPrintable

    • generic, x86
    • generic, windows_95

      Name: gsC80088 Date: 11/17/98


      I was unable to display system fonts although I
      was able to use getAllFonts() but the fonts
      derived from the fonts retrieved by getAllFonts()
      by using deriveFont(int st, float si) do not display
      themselve. i.e. render themselves.


      // =====================================
      // Authored by: Parminder S. Lehal
      // Developed by: Parm's Java Editor
      // Date: Thu Sep 17 10:43:02 1998
      // Version: 1.0
      // email: ###@###.###
      // import classes------------------
      import java.awt.*;
      import java.awt.event.*;
      public class fontlist extends Frame implements ActionListener, WindowListener {

          Button b1 = null;
          Button b2 = null;
          Label la[] = new Label[100];
          Label la2 = null;
          Label la3 = null;
          TextArea ta1 = null;
          Panel pa1 = null;
          Panel pa2 = null;
          Panel pa3 = null;
          Panel pa4 = null;

          fontlist () {
              super("fontlist");
              addWindowListener(this);

              pa1 = new Panel();
              pa2 = new Panel();
              pa3 = new Panel();
              pa4 = new Panel();
              b1 = new Button("List All Fonts now");
              b1.addActionListener(this);
              b1.setBackground(new Color(190, 190, 255));
              b1.setForeground(new Color(255, 20, 20));
              b1.setActionCommand("b1");
              b2 = new Button("Close");
              b2.addActionListener(this);
              b2.setBackground(new Color(190, 190, 255));
              b2.setForeground(new Color(255, 20, 20));
              b2.setActionCommand("b2");
              pa1.add(b1);
              pa1.add(b2);
              add("North", pa1);
              add("Center", pa2);
              pa2.setLayout(new GridLayout(0, 3));
              for (int n = 0; n < 100; n++) {
                  la[n] = new Label("");
                  pa2.add(la[n]);
              }
          }

          public static void main(String[] arg) {
              fontlist parm = new fontlist ();

              parm.pack();
              parm.show();

              parm.setSize(600, 500);
          }

          public void actionPerformed(ActionEvent e) {
              String ob = e.getActionCommand();

              if (ob == "b1") {
                  fontlist ();
              }
              if (ob == "b2") {
                  System.exit(0);
              }
          }
          // ===========define Window
          // Listener========================
          public void windowClosing(WindowEvent event) {
              dispose();
              System.exit(0);
          }
          public void windowOpened(WindowEvent event) {
          }
          public void windowIconified(WindowEvent event) {
          }
          public void windowDeiconified(WindowEvent event) {
          }
          public void windowClosed(WindowEvent event) {
          }
          public void windowActivated(WindowEvent event) {
          }
          public void windowDeactivated(WindowEvent event) {
          }
          // =======================================================
          // =====
          public void fontlist () {
              String fll = "";
              Font f1 = new Font("parm", 0, 15);
              GraphicsEnvironment tk1 = GraphicsEnvironment.getLocalGraphicsEnvironment();
              Toolkit tk = Toolkit.getDefaultToolkit();
              Font[] fl = tk1.getAllFonts();
              Font[] fontall = new Font[fl.length];
              for (int n = 0; n < fl.length; n++) {
                  fll = fl[n].getFontName();
                  fontall[n] = fl[n].deriveFont(fl[n].getStyle(), 15);
                  la[n].setFont(fontall[n]);
                  la[n].setText(fll);
              }
              tk.beep();
          }
      }
      (Review ID: 39031)
      ======================================================================

            Unassigned Unassigned
            gstone Greg Stone
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: