Java Swing Icon setComponentTabIcon(Component component, Icon icon)

Here you can find the source of setComponentTabIcon(Component component, Icon icon)

Description

set Component Tab Icon

License

Apache License

Declaration

public static void setComponentTabIcon(Component component, Icon icon) 

Method Source Code


//package com.java2s;
/*/*ww  w.j a  va  2s .c om*/
 * Copyright 2012-2014 Dan Cioca
 *
 * Licensed 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 javax.swing.Icon;
import javax.swing.JTabbedPane;

import java.awt.Component;

public class Main {
    public static void setComponentTabIcon(Component component, Icon icon) {
        Component parent = component.getParent();
        while (parent != null) {
            if (parent instanceof JTabbedPane) {
                JTabbedPane tabbedPane = (JTabbedPane) parent;
                int index = tabbedPane.indexOfComponent(component);
                tabbedPane.setIconAt(index, icon);
                break;
            }
            component = parent;
            parent = parent.getParent();
        }
    }
}

Related

  1. mergeComponentAndIcon(JComponent component, Icon icon)
  2. mergeIcons(Icon i1, Icon i2, int offsetRechtsOben)
  3. reescala(Icon ic, int maxW, int maxH)
  4. resize(Icon icon, int width, int height)
  5. scaleDown(Icon icon, int maxWidth, int maxHeight)
  6. sizeToIcon(JComponent component, Icon icon)