ToggleButton HTML Text Font ändern

shocking

Mitglied
Hi Leute,

ich möchte einen Button mit einem 2-zeiligen Text erstellen. Das geht ja bekanntlich über HTML. Mein Problem ist nun dass der Text fett sein soll, wenn der Button selektiert ist.

Deswegen habe ich die Paint-Methode meines Buttons überschrieben wie folgt:

Code:
  public void paint( Graphics g, JComponent c )
  {
    NavigationButton b = ( NavigationButton )c;

    // get icon according to state
    Icon background = getBackground( b.getModel() );
    if( background != null )
    {
      background.paintIcon( c, g, 0, 0 );
    }
    
// super paint overriden
    ButtonModel model = b.getModel();

    String text = layout( b, SwingUtilities2.getFontMetrics( b, g ), b.getWidth(), b.getHeight() );

    clearTextShiftOffset();

    // perform UI specific press action, e.g. Windows L&F shifts text
    if( model.isArmed() && model.isPressed() )
    {
      paintButtonPressed( g, b );
    }

    // Paint the Icon
    if( b.getIcon() != null )
    {
      paintIcon( g, c, iconRect );
    }

    if( text != null && !text.equals( "" ) )
    {
      View v = ( View )c.getClientProperty( BasicHTML.propertyKey );
      if( v != null )
      {
        
        Graphics2D g2D = ( Graphics2D )g;

        AffineTransform transform = g2D.getTransform();
        // text should be displayed left and not centered
        g2D.translate( -15, 0 );
        Font font = g2D.getFont();
                
        if( model.isSelected() )
        {
          g2D.setFont( new Font( font.getName(), Font.BOLD, font.getSize() ) );
        }

        v.paint( g2D, textRect );
        g2D.setTransform( transform );
      }
      else
      {
        paintText( g, b, textRect, text );
      }
    }

    if( b.isFocusPainted() && b.hasFocus() )
    {
      // paint UI specific focus
      paintFocus( g, b, viewRect, textRect, iconRect );
    }
  }

Das funktioniert aber leider nicht. Der Text ist zwar korrekt ausgerichtet, aber er idst nicht fett. Wie kann ich also die Font auf BOLD setzen für die View?

Vielen Dank
shocking
 

Neue Beiträge

Zurück