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

StyledDocument/JTextPane ignore FontFamily attribute

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 1.2.0
    • client-libs
    • 2d
    • x86
    • solaris_2.6

    Description



      Name: rm29839 Date: 04/08/98


      The following test case attempts to display
      each font family name within a JTextPane
      using the font itself.
      But as you will see, the font remains the
      same. The "addAttribute" method of
      StyleContext doesn't appear to recognize
      "StyleConstants.FontFamily". Or am I doing
      something wrong?
      Here is the testcase:
      ---------------------------------------
      import java.awt.Toolkit;
      import java.awt.swing.text.AttributeSet;
      import java.awt.swing.text.StyleConstants;
      import java.awt.swing.text.StyleContext;
      import java.awt.swing.text.DefaultStyledDocument;
      import java.awt.swing.text.StyledDocument;
      import java.awt.swing.JTextPane;
      import java.awt.swing.JScrollPane;
      import java.awt.swing.JFrame;

      class FontTest {
          public static void main(String args[]){
              String fonts[] = Toolkit.getDefaultToolkit().getFontList();
              StyledDocument doc = new DefaultStyledDocument();
              JTextPane pane = new JTextPane(doc);
              JScrollPane scroller = new JScrollPane(pane);
              JFrame f = new JFrame();
              f.getContentPane().add(scroller);
              f.pack();
              f.setSize(300,600);
              f.show();

              for (int i =0; i < fonts.length; i++){
                  String font= fonts[i];
                  append(doc,font);
                  scroller.validate();
                  }
              }

          static void append(StyledDocument doc, String font)
              {
              int loc = doc.getLength();
              StyleContext s = StyleContext.getDefaultStyleContext();
              AttributeSet def = doc.getDefaultRootElement().getAttributes();
              AttributeSet attr = s.addAttribute(
                                      def,
                                      StyleConstants.FontFamily,font);
              try{
                  doc.insertString(loc,font+"\n",attr);
                  }
              catch(Exception x){}
              }
          }
      (Review ID: 27176)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              pcharltosunw Paul Charlton (Inactive)
              rmandelsunw Ronan Mandel (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: