Java JLabel getStroke(final JLabel _jlbl_stroke)

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

Description

Apply stroke on background.

License

Apache License

Parameter

Parameter Description
_jlbl_stroke the background carrying item.

Return

the stroked image.

Declaration

public static BufferedImage getStroke(final JLabel _jlbl_stroke) 

Method Source Code


//package com.java2s;
/*//w  w w . j  av  a 2  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.IllegalComponentStateException;

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.
     * @return the stroked image.
     */
    public static BufferedImage getStroke(final JLabel _jlbl_stroke) {

        final int strokeDistance = 10;
        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) {

                    try {
                        if ((x + _jlbl_stroke.getLocationOnScreen().x + y + _jlbl_stroke.getLocationOnScreen().y)
                                % strokeDistance == 0) {
                            final int clr = 10;
                            bi_stroke.setRGB(x, y, new Color(clr, clr, clr, clr).getRGB());
                        } else {

                            final int clr = 0;
                            bi_stroke.setRGB(x, y, new Color(clr, clr, clr, clr).getRGB());
                        }
                    } catch (IllegalComponentStateException e) {
                        x = bi_stroke.getWidth();
                        y = bi_stroke.getHeight();
                    }

                }
            }
            _jlbl_stroke.setIcon(new ImageIcon(bi_stroke));
            return bi_stroke;
        }
        return null;

    }
}

Related

  1. extendByIcon(JLabel label, Dimension dm)
  2. findMaxLabelWidth(JLabel... jLabels)
  3. getLabelValue(JLabel lbl)
  4. getRoughStroke(final JLabel _jlbl_stroke)
  5. getStoredBackground(JLabel comp)
  6. getTimeWidth(JLabel label)
  7. highlightLabel(JLabel label)
  8. leftAlignJLabel(JLabel label)
  9. parseIntFromLabel(JLabel jLabel)