< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLabelUI.java

Print this page




 162      * Paints the label text with the foreground color, if the label is opaque
 163      * then paints the entire background with the background color. The Label
 164      * text is drawn by {@link #paintEnabledText} or {@link #paintDisabledText}.
 165      * The locations of the label parts are computed by {@link #layoutCL}.
 166      *
 167      * @see #paintEnabledText
 168      * @see #paintDisabledText
 169      * @see #layoutCL
 170      */
 171     public void paint(Graphics g, JComponent c)
 172     {
 173         JLabel label = (JLabel)c;
 174         String text = label.getText();
 175         Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
 176 
 177         if ((icon == null) && (text == null)) {
 178             return;
 179         }
 180 
 181         FontMetrics fm = SwingUtilities2.getFontMetrics(label, g);

 182         String clippedText = layout(label, fm, c.getWidth(), c.getHeight());
 183 
 184         if (icon != null) {
 185             icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
 186         }
 187 
 188         if (text != null) {
 189             View v = (View) c.getClientProperty(BasicHTML.propertyKey);
 190             if (v != null) {
 191                 v.paint(g, paintTextR);
 192             } else {
 193                 int textX = paintTextR.x;
 194                 int textY = paintTextR.y + fm.getAscent();
 195 
 196                 if (label.isEnabled()) {
 197                     paintEnabledText(label, g, clippedText, textX, textY);
 198                 }
 199                 else {
 200                     paintDisabledText(label, g, clippedText, textX, textY);
 201                 }




 162      * Paints the label text with the foreground color, if the label is opaque
 163      * then paints the entire background with the background color. The Label
 164      * text is drawn by {@link #paintEnabledText} or {@link #paintDisabledText}.
 165      * The locations of the label parts are computed by {@link #layoutCL}.
 166      *
 167      * @see #paintEnabledText
 168      * @see #paintDisabledText
 169      * @see #layoutCL
 170      */
 171     public void paint(Graphics g, JComponent c)
 172     {
 173         JLabel label = (JLabel)c;
 174         String text = label.getText();
 175         Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
 176 
 177         if ((icon == null) && (text == null)) {
 178             return;
 179         }
 180 
 181         FontMetrics fm = SwingUtilities2.getFontMetrics(label, g);
 182         label.updateUI();
 183         String clippedText = layout(label, fm, c.getWidth(), c.getHeight());
 184 
 185         if (icon != null) {
 186             icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
 187         }
 188 
 189         if (text != null) {
 190             View v = (View) c.getClientProperty(BasicHTML.propertyKey);
 191             if (v != null) {
 192                 v.paint(g, paintTextR);
 193             } else {
 194                 int textX = paintTextR.x;
 195                 int textY = paintTextR.y + fm.getAscent();
 196 
 197                 if (label.isEnabled()) {
 198                     paintEnabledText(label, g, clippedText, textX, textY);
 199                 }
 200                 else {
 201                     paintDisabledText(label, g, clippedText, textX, textY);
 202                 }


< prev index next >