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

Bold and Italic attributes don't work properly.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • client-libs
    • 2d
    • beta
    • x86
    • windows_nt



      Name: rmT116609 Date: 09/15/2000


      java version 1.3.0
      Java 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot Client VM (build 1.3.0-C, mixed mode)

      The bold and italic fonts aren't rendered properly. Just compile the following
      code and you can see what I mean:

      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;


      //----------------------------------------------------------------

      public class Fonts
      {
      public static void main(String[] args)
      {
              JFrame frame = new MainFrame();
              frame.pack();
              frame.show();
      }
      }

      //----------------------------------------------------------------

      class MainFrame extends JFrame
      {
          public MainFrame()
          {
              setTitle("Fonts: Bold and Italic do not seem to work");
              setLocation(300, 300);

              addWindowListener(new WindowAdapter()
              { public void windowClosing(WindowEvent e) { System.exit(0); }});

              getContentPane().add(new FontPanel());
          }
      }

      //----------------------------------------------------------------

      class FontPanel extends JPanel implements ItemListener
      {
          JComboBox combo;
          Font[] fonts;
          JTextField text;

          public FontPanel()
          {
              text = new JTextField("Font Sample");
              text.setEditable(false);
              text.setBackground(Color.white);
              text.setBorder(BorderFactory.createEtchedBorder());

              combo = new JComboBox();
              combo.addItemListener(this);
              /*
              This statement creates a 1 point version of ALL of the fonts - and
      their variants - that
              are on the system. This means, for example, instead of getting
      just "Courier New" you get
              "Courier New", "Courier New Bold", "Courier New Italic", and "Courier
      New Bold Italic".
              On my system, the number of font names (retrieved
      by 'getAvailableFontFamilyNames()')
              grew from 85 to 143 due to all of these variants now being listed.
              */
              fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();

              for (int i = 0; i < fonts.length; i++)
                  combo.addItem(fonts[i].getFontName());

              setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
              add(combo);
              add(text);
              add(Box.createHorizontalStrut(50));
          }

          public void itemStateChanged(ItemEvent anEvent)
          {
              if (anEvent.getStateChange() == ItemEvent.DESELECTED)
                  return;

              /* This statement should create a new font with the same style and the
      specified size.
               Bold and italic attributes do not seem to be working.
      */
              text.setFont(fonts[combo.getSelectedIndex()].deriveFont(19.0F));

              text.invalidate();
              validate();
          }
      }
      (Review ID: 108216)
      ======================================================================

            pkejriwasunw Parry Kejriwal (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: