Java JLabel getRoughStroke(final JLabel _jlbl_stroke)

Here you can find the source of getRoughStroke(final JLabel _jlbl_stroke)

Description

Apply stroke on background.

License

Apache License

Parameter

Parameter Description
_jlbl_stroke the background carrying item.

Declaration

public static void getRoughStroke(final JLabel _jlbl_stroke) 

Method Source Code


//package com.java2s;
/*/*ww  w  . j  a va2  s.c  o m*/
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.Color;

import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;

import javax.swing.JLabel;

public class Main {
    /**
     * Apply stroke on background.
     * @param _jlbl_stroke the background carrying item.
     */
    public static void getRoughStroke(final JLabel _jlbl_stroke) {

        final int strokeDistance = 20;
        if (_jlbl_stroke.getWidth() > 0 && _jlbl_stroke.getHeight() > 0
        //            && jlbl_stroke.isShowing()
        ) {
            BufferedImage bi_stroke = new BufferedImage(_jlbl_stroke.getWidth(), _jlbl_stroke.getHeight(),
                    BufferedImage.TYPE_INT_ARGB);

            for (int x = 0; x < bi_stroke.getWidth(); x++) {

                for (int y = 0; y < bi_stroke.getHeight(); y++) {

                    //                  if ( (_addX + x + y +  _addY) % 20 == 0) {
                    if ((x + y) % strokeDistance == 0) {

                        final int r = 40, g = 50, alpha = 90;
                        bi_stroke.setRGB(x, y, new Color(r, g, g, alpha).getRGB());
                    } else {

                        bi_stroke.setRGB(x, y, new Color(0, 0, 0, 0).getRGB());
                    }
                }
            }
            _jlbl_stroke.setIcon(new ImageIcon(bi_stroke));
        }

    }
}

Related

  1. ensureCustomBackgroundStored(JLabel comp)
  2. exibeMensagemTemporaria(final JLabel lblMensagem, String mensagem)
  3. extendByIcon(JLabel label, Dimension dm)
  4. findMaxLabelWidth(JLabel... jLabels)
  5. getLabelValue(JLabel lbl)
  6. getStoredBackground(JLabel comp)
  7. getStroke(final JLabel _jlbl_stroke)
  8. getTimeWidth(JLabel label)
  9. highlightLabel(JLabel label)