2 Replies Latest reply on Aug 28, 2012 8:15 PM by rayc

    Add JButton to JTabbedPane tab

      Adding a JButton to a JTabbedPane tab is well documented. However, is there a way to make sure that the JButton completely fills the tab area so that when the user clicks on JButton it is not possible to click on the tab area.
        • 1. Re: Add JButton to JTabbedPane tab
          Could you please elaborate more on your query as in what exactly you are looking for.

          import java.awt.BorderLayout;
          import javax.swing.JButton;
          import javax.swing.JFrame;
          import javax.swing.JPanel;
          import javax.swing.JTabbedPane;

          public class TabbedPaneExample extends JFrame
               private static final long serialVersionUID = 1L;

                    JTabbedPane tabbedPane = new JTabbedPane();
                    setTitle( "Tabbed Pane Application" );
                    setSize( 300, 200 );
                    JPanel topPanel = new JPanel();
                    topPanel.setLayout( new BorderLayout() );
                    getContentPane().add( topPanel );
                    JPanel panel = new JPanel();
                    JButton button = new JButton("Click!");
                    topPanel.add( tabbedPane, BorderLayout.CENTER );

               public static void main(String[] args)
                    TabbedPaneExample obj = new TabbedPaneExample();


          • 2. Re: Add JButton to JTabbedPane tab
            Thanks for the short code sample.
            In the tab, where you have the text "Hello", if that was a JButton which filled the whole tab(i.e. where the word "Hello" is) then that is exactly what I am trying to achieve. It should not be possible to activate the ChangeListener for this tab. Other tabs should be unaffected and should operate as normal.