I am using JtabbedPane which contains several jTextPanes like jTextPane1,lTextPane2...etc. NOw I want to perform some actions during the selection of a partiular tab. eg: I want to enable a button if I select jTextPane 2.. Now I am able to identify selected Component of Tab.ie: jTextPane. But I am not able to identify which jTextPane is selected(Which object of jTextPane).. How can I resolve it ..? Can any one help me? plz..

to find out which pane is selected try using getSelectedIndex() which will tell you which pane is currently selected.

try using something like this if you want the code to be ran as soon as that pane has been selected.

private void jTabbedPane1MouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
        if( jTabbedPane1.getSelectedIndex()== 0)
        {
            function1();
        }
        if( jTabbedPane1.getSelectedIndex()== 1)
        {
            function2();
        }
    }

    private void function1()
    {
       jTabbedPane1.setBackground(Color.red);
    }
    private void function2()
    {
        jTabbedPane1.setBackground(Color.green);
    }

I've not used Tabbed Panes before so this might not be the best way of doing it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.