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

Show an empty choice control then fill it, overlaps other controls

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_nt

      Description

      Win32 only: Empty choice controls that are shown then filled with data overlap adjacent controls.

      Steps to reproduce
      Compile the attached code
      Save attached FontTest.html
      Run appletviewer FontTest.html

      // note location of choice controls

      /* Font test routines
       * %W% %G% %U%
       * @author Kevin A. Smith
       */

      import java.awt.*;
      import java.util.Properties;
      import java.applet.Applet;

      public class FontTest extends Applet
      {
          // class variables
          private Choice fontNameList;
          private TextField fontSize;
          private TextArea textArea;
          private TextField fontInfo;
          private Checkbox fontBold;
          private Checkbox fontItalic;
          private Choice fontInfoChoice;
          private Choice fontMetricsList;
          private TextField metricInfo;

          private final int DEF_FONT_SIZE = 12;

          private final String infoTypes[] =
          {
             "getFamily",
             "getName",
             "getSize",
             "getStyle",
             "hashCode",
             "isBold",
             "isItalic",
             "isPlain",
             "toString"
          };

          private final String metricTypes[] =
          {
             "bytesWidth",
             "charWidth",
             "charsWidth",
             "getAscent",
             "getDescent",
             "getFont",
             "getHeight",
             "getLeading",
             "getMaxAdvance",
             "getMaxDecent",
             "getMaxDescent",
             "getWidths",
             "stringWidth",
             "toString"
          };

          // create screen objects
          public FontTest()
          {
             // local variables
             Panel fontsPanel = new Panel();
             Panel tempPanel = new Panel();

             fontsPanel.setLayout( new GridLayout(3, 1) );

             // create first panel
             tempPanel.add( new Label("Font Name:") );
             tempPanel.add( fontNameList = new Choice() );
             tempPanel.add( new Label("Size:") );
             tempPanel.add( fontSize = new TextField(
                                     Integer.toString(DEF_FONT_SIZE),
                                     3) );
             tempPanel.add( new Label("Style:") );
             tempPanel.add( fontBold = new Checkbox("Bold") );
             tempPanel.add( fontItalic = new Checkbox("Italic") );
             fontsPanel.add( tempPanel );

             // create second panel
             tempPanel = new Panel();
             tempPanel.add( new Label("Font") );
             tempPanel.add( fontInfoChoice = new Choice() );
             tempPanel.add( fontInfo = new TextField("Unknown method", 40) );
             fontInfo.setEditable(false);
             fontsPanel.add( tempPanel );

             // font metrics stuff
             tempPanel = new Panel();
             tempPanel.add( new Label("Font Metrics") );
             tempPanel.add( fontMetricsList = new Choice() );
             tempPanel.add( metricInfo = new TextField("Unknown metric", 40) );
             metricInfo.setEditable(false);
             fontsPanel.add( tempPanel );

             // place panels into applet
             setLayout( new BorderLayout() );
             add( "North", fontsPanel );
             add( "Center", textArea = new TextArea(100, 10) );
          
          }

          // initialize screen objects
          public void init()
          {
             // local variables
             Properties properties = new Properties();
             int i;
             String fontNames[];

             /* Notes
              * If you addItem() to the choice controls in
              * the constructor, the problem does not appear.
              * The appletviewer shows these controls before
              * calling applet.init().
              */

             // get list of fonts and populate choice list
             fontNames = getToolkit().getFontList();
             for (i = 0; i < fontNames.length; ++i)
                fontNameList.addItem( fontNames[i] );

             // add additional font choices
             fontNameList.addItem("Default Font");
             fontNameList.addItem("Current Font");

             // set font method names
             for (i = 0; i < infoTypes.length; ++i)
                fontInfoChoice.addItem( infoTypes[i] );

             // set Metrics info choice
             for (i = 0; i < metricTypes.length; ++i)
                fontMetricsList.addItem( metricTypes[i] );


             // set the initial values
             setTextFont();

              // default properties
             properties.put("Default Test Font", "Courier-bold-16" );
             System.setProperties(properties);

             resize(600, 400);
          }

          public boolean action(Event evt, Object obj)
          {
             // check type of event
             if ( (evt.target instanceof TextField) ||
                  (evt.target instanceof Checkbox) )
             {
                setTextFont();
                return true;
             }
             else if (evt.target instanceof Choice)
             {
                if ( evt.target.equals(fontNameList) )
                   setTextFont();
                else if ( evt.target.equals(fontMetricsList) )
                   getMetrics();
                else if ( evt.target.equals(fontInfoChoice) )
                   getFontInfo();
                else
                   return false;

                return true;
             }
             else
                return super.action(evt, obj);

          }

          private void setTextFont()
          {
             // local variables
             Font font;
             String fontName;
             int iFontSize;
             int fontStyle;

             // Get fontName
             fontName = fontNameList.getSelectedItem();
             if ( fontName.equals("Default Font") )
                font = ( Font.getFont("Default Test Font") );
             else if ( fontName.equals("Current Font") )
                font = ( Font.getFont("Current Font", textArea.getFont() ) );
             // create a font from scratch
             else
             {
                // get font size
                try
                {
                   iFontSize = Integer.parseInt( fontSize.getText() );
                }
                catch(NumberFormatException e)
                {
                   iFontSize = DEF_FONT_SIZE;
                }
             
                // get Font Style
                if ( fontBold.getState() )
                   fontStyle = Font.BOLD;
                else
                   fontStyle = Font.PLAIN;

                if ( fontItalic.getState() )
                   fontStyle = fontStyle | Font.ITALIC;

                // create the new font
                 font = new Font(fontName, fontStyle, iFontSize);
             } // end else create new font

             // set the text area font
             if (! font.equals( textArea.getFont() ) )
             {
                textArea.setFont(font);
                fontSize.setText( Integer.toString( font.getSize() ) );
             }

             // now report back the info from this font
             getFontInfo();
             getMetrics();

          }

          private void getFontInfo()
          {
                fontInfo.setText("Unknown method call");
          }

          private void getMetrics()
          {
                metricInfo.setText("Unknown Font Metric");
          }

      }


      ----- FontTest.html -----
      <APPLET CODE = "FontTest.class" WIDTH = 600 HEIGHT = 400>
      </APPLET>

        Attachments

          Activity

            People

            Assignee:
            tballsunw Tom Ball (Inactive)
            Reporter:
            kasmithsunw Kevin Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: