How do I add disabled icon for JTabbedPane tabs?

When adding a tabs to JTabbedPane you can define the icon for the tabs. This icon will be displayed beside the tab’s title in enable or disable state of the tabs. To make the user interface better you can also define a disabled icon for the tab. This icon will be displayed when the state of the tabs are disabled.

To assign a disabled icon for the tab use the JTabbedPane‘s setDisabledIconAt(int index, Icon icon) method. As always the index parameter is zero-based which means the first tab is at index number 0. The icon parameter is the disabled icon of your tabs.

package org.kodejava.swing;

import javax.swing.*;
import java.awt.*;
import java.util.Objects;

public class TabbedPaneDisableIcon extends JPanel {
    private final ImageIcon[] disableIcons = {
            new ImageIcon(Objects.requireNonNull(
            new ImageIcon(Objects.requireNonNull(
            new ImageIcon(Objects.requireNonNull(

    public TabbedPaneDisableIcon() {

    public static void showFrame() {
        JPanel panel = new TabbedPaneDisableIcon();

        JFrame frame = new JFrame("JTabbedPane Demo");

    public static void main(String[] args) {

    private void initializeUI() {
        this.setLayout(new BorderLayout());
        this.setPreferredSize(new Dimension(500, 200));

        JTabbedPane pane = new JTabbedPane();

        ImageIcon tab1Icon = new ImageIcon(Objects.requireNonNull(
        ImageIcon tab2Icon = new ImageIcon(Objects.requireNonNull(
        ImageIcon tab3Icon = new ImageIcon(Objects.requireNonNull(
        JPanel content1 = new JPanel();
        JPanel content2 = new JPanel();
        JPanel content3 = new JPanel();

        pane.addTab("Pass", tab1Icon, content1);
        pane.addTab("Fail", tab2Icon, content2);
        pane.addTab("Error", tab3Icon, content3);

        for (int i = 0; i < pane.getTabCount(); i++) {
            pane.setDisabledIconAt(i, disableIcons[i]);

        // Disable the last tab to see the disabled icon displayed.
        pane.setEnabledAt(pane.getTabCount() - 1, false);

        this.add(pane, BorderLayout.CENTER);

The result of the code snippet above is:

Set Disabled Icon for JTabbedPane Tabs

Set Disabled Icon for JTabbedPane Tabs

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.