ERLEDIGT
JA
JA
ANTWORTEN
0
0
ZUGRIFFE
1759
1759
EMPFEHLEN
-
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 :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
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
Ähnliche Themen
-
iFrame Text auslesen (ohne HTML-Tags, reiner Text... wysiwyg)
Von Fabian Frank im Forum Javascript & AjaxAntworten: 6Letzter Beitrag: 06.06.10, 03:35 -
ToggleButton
Von retuzi im Forum Visual Basic 6.0Antworten: 2Letzter Beitrag: 09.05.07, 17:13 -
Font in erster JTable Zeile ändern
Von eusti im Forum JavaAntworten: 4Letzter Beitrag: 03.10.06, 16:40 -
Font und Fontfarbe im CRichEditCtrl ändern
Von NinjaOne im Forum VisualStudio & MFCAntworten: 5Letzter Beitrag: 29.07.05, 23:37 -
Font in HTML einbinden ?
Von MyOwnWorld im Forum HTML & XHTMLAntworten: 2Letzter Beitrag: 27.11.03, 16:56





Zitieren
Login





