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

add outline and other text effects to JLabel

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: client-libs

      Description

      A DESCRIPTION OF THE REQUEST :
      There is no easy way to create controls with outlined text and other text effects like shading etc. I have subclassed JPanel, and I draw outlined text inside, however, I cannot reuse this code to have outined text in buttons etc. Therefore, the proper place to have this feature is in JLable, which automatically will make it available to other controls.

      JUSTIFICATION :
      Without this in JLabel, one needs to reimplement all the controls where he needs text effects.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      JLable with some attributes for text effects, or somehow attaching a renderer and drawing component to JLabel.

      ---------- BEGIN SOURCE ----------
      Originally the idea was suggested somewhere on the net (cut and paste directly from my application):

               g2d = ( Graphics2D )image_.getGraphics( );
               Composite prevComposite = g2d.getComposite( );
               g2d.setComposite( AlphaComposite.getInstance( AlphaComposite.CLEAR, 0.0f ) );
               rect.x = 0;
               rect.y = 0;
               g2d.fill( rect );
               g2d.setComposite( prevComposite );

               g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
                                     RenderingHints.VALUE_ANTIALIAS_ON );
               g2d.setRenderingHint( RenderingHints.KEY_RENDERING,
                                     RenderingHints.VALUE_RENDER_QUALITY);
         
               double timeBeg = System.currentTimeMillis( );
               if( name_.length( ) > 0 )
               {
                  int x = ProgramSettings.getInt( "PlayerInfoTextX" );
                  int y = ProgramSettings.getInt( "PlayerInfoTextY" );
         
                  Font font = getFont( );
         
                  FontMetrics fontMetrics = g2d.getFontMetrics( font );
                  int fontAscent = fontMetrics.getMaxAscent( );
         
                  g2d.setFont( font );
         
                  FontRenderContext frc = g2d.getFontRenderContext( );
                  TextLayout tl = new TextLayout( name_, getFont( ), frc );
         
                  Shape src = tl.getOutline( null );
         
                  float xText = x;
                  float yText = y + tl.getAscent( );
         
                  AffineTransform shift =
                     AffineTransform.getTranslateInstance( xText, yText );
                  Shape shp = shift.createTransformedShape( src );
         
                  g2d.setColor( Color.BLACK );
                  g2d.setStroke( new BasicStroke( 3f ) );
                  g2d.draw( shp );
         
                  g2d.setColor( Color.WHITE );
                  g2d.fill( shp );
               }

      ---------- END SOURCE ----------
      ###@###.### 2005-06-15 11:26:40 GMT

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              jssunw Jitender S (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: