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 8910025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:35:05+00:00 2026-06-15T03:35:05+00:00

I have a JTappedPane with a button on that I want to make close

  • 0

I have a JTappedPane with a button on that I want to make close that tab.
I am doing it like so:

jTabbedPane1.addTab(title, null, panel, null);

JPanel pnl = new JPanel();
    JButton close = new JButton();
    try {
        Image img = ImageIO.read(getClass().getResource("x.png"));
        close.setIcon(new ImageIcon(img));
      } catch (IOException ex) {
          ex.printStackTrace();
      }
    close.setPreferredSize(new Dimension(10, 10));
    close.setBorderPainted(false);
    close.addActionListener(new java.awt.event.ActionListener(){

        public void actionPerformed(ActionEvent evt) {
                    //TODO CLOSE THE TAP WHEN BUTTON IS PRESSED

                }

        }});
    JLabel lab = new JLabel(s);

     pnl.setOpaque(false);
     pnl.add(lab);
      pnl.add(close);

jTabbedPane1.setTabComponentAt(jTabbedPane1.getTabCount() - 1, pnl);

I am trying to get the title of the tab on the tab that the button has been pressed on.
I thought i could do something like
close.getContaining() to return the tab it is on but I was wrong.

Any Ideas?

  • 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-06-15T03:35:06+00:00Added an answer on June 15, 2026 at 3:35 am

    If I understand you correctly, you want to find the index of the tab which has the parent of the button as tabComponent:

    public void actionPerformed(ActionEvent evt) {
        JComponent source = (JComponent) evt.getSource();
        Container tabComponent = source.getParent();
        int tabIndex = jTabbedPane1.indexOfTabComponent(tabComponent);
        jTabbedPane1.removeTabAt(tabIndex);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a JToolBar that have all the controls like add, edit,
I have a JTabbedPane with a custom tab component. That component contains a JLabel
I have an application that has multiple panels; I would like to have the
I have this class inside my main class to put a close button on
I use a jtabbedpane. for each tab it will have a panel and some
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I have an application using JtabbedPane. Each tab is a JPanel. I wrote a
I have an application that includes a JTabbedPane and two tabs with some components.
I have specific classes that i need to load. There name are stored in
I have VTreePanel class that extends from CPanel which extends from JPanel. The class

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.