Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7069609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:27:58+00:00 2026-05-28T05:27:58+00:00

I have created a swing application as bellow which shows main tasks in tabs

  • 0

I have created a swing application as bellow which shows main tasks in tabs when clicking the buttons which are related to specific tasks. I have added a small close button to each tab and what I need to to is close the tab when clicking the close button related to that tab.

enter image description here

The close button is in a class which is extended fron JPanel class as bellow,

public class CloseTab extends JPanel {

    JLabel title = new JLabel();
    JButton closeButton = new JButton();
    int tabIndex;
    JTabbedPane tabbedPane = null;
    public static int SELECTED_TAB_INDEX;
    .
    .
    .    

    public static void setSELECTED_TAB_INDEX(int SELECTED_TAB_INDEX) {
        CloseTab.SELECTED_TAB_INDEX = SELECTED_TAB_INDEX;
    }

    .
    .

    public void setCloseAction(ActionListener al) {
        closeButton.addActionListener(al);
        closeButton.setSize(10, 10);
        closeButton.setBorder(new EmptyBorder(0, 0, 0, 0));
        closeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ofm/mnu/icons/delete.gif")));

    }

    public void setTabIndex(int index) {
        this.tabIndex = index;
        System.out.println(tabIndex);
    }

    public void init() {
        add(title);
        add(closeButton);
        setOpaque(false);
        setCloseAction(closeActoion);      

    }



    ActionListener closeActoion = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // System.out.println(tabIndex);
            if(tabbedPane.getTabCount() != 0 && tabbedPane.getSelectedIndex() == SELECTED_TAB_INDEX){
                tabbedPane.remove(SELECTED_TAB_INDEX);
            }   
        }
    };

}

and in the main frame I seted the SELECTED_TAB_INDEX variable as follow,

tbpWorkSpace.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                JTabbedPane a = (JTabbedPane) e.getSource();
                CloseTab pnl = new CloseTab();                
                pnl.setSELECTED_TAB_INDEX(a.getSelectedIndex());
            }
        });

but, I couldn’t get the result I wanted please tell me is there any other way to achieve the result I want.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:27:59+00:00Added an answer on May 28, 2026 at 5:27 am

    To remove tab use .remove(index) method of JTabbedPane. Learn more here: How to Use Tabbed Panes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created in my Java Swing application a main window with a JButton.
I have created general bill maker application on swing in which i've to print
I have created one java-swing application. The application runs perfectly runs perfect on my
I have a Swing application in which I have multiple windows with different goals
I have created a Swing Application- GUI containing fields like TextFields, Labels, CheckBoxes and
Hi I have created a swing application using java 1.5 and i created a
Hi I have created a sample java swing application Mac os. Now I want
I have created an application which requires the reloading of an image several times
I have created a Java Swing application using JDK 1.6. Many customers are asking
I have created an .exe file of my software (which is a Java swing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.