5

I have a tabbed pane including five tabs on it . This tabbed pane is on a JPanel I use a button on another JPanel to get fourth tab as leading tab . But when I click on the button first tab is still display and I have to move to the fourth one manually . Have any ideas . Thanks in deep.

Button action

Center instance1 = Center.getInstance();
instance1.doClickHistoryBtn();

doClickHistoryBtn() method

public void doClickHistoryBtn(){
    history_btn.doClick();
}

When I execute this doClickHistoryBtn() method , History_panel is loading.

second JPanel (History_panel)

private JPanel history_panel1;
private JPanel history_panel2;
private JPanel history_panel3;
private JPanel history_panel4;
private JPanel history_panel5;

public History_panel()
{
    initComponents();
    setPanels();
}   

private void setPanels(){    

}

first screen image

This is my first screen.

Expected

changed image

Actual

result image

Viral Patel
  • 32,418
  • 18
  • 82
  • 110
Terance Wijesuriya
  • 1,928
  • 9
  • 31
  • 61
  • Consider providing a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This is not a code dump, but an example of what you are doing which highlights the problem you are having. This will result in less confusion and better responses – MadProgrammer Jan 12 '16 at 04:32
  • 2
    [`JTabbedPane#setSelectedIndex`](https://docs.oracle.com/javase/8/docs/api/javax/swing/JTabbedPane.html#setSelectedIndex-int-) or [`JTabbedPane#setSelectedComponent`](https://docs.oracle.com/javase/8/docs/api/javax/swing/JTabbedPane.html#setSelectedComponent-java.awt.Component-) – MadProgrammer Jan 12 '16 at 04:33
  • JTabbedPane#setSelectedIndex – Terance Wijesuriya Jan 12 '16 at 04:41

1 Answers1

2

JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.setSelectedIndex(3);

Above code will do it In setSelectedIndex() method you have to pass the index of the tabbedpane you want to set as default. And it will open that pane whose index u will providing as argument to the setSelectedIndex().

Mrinmoy
  • 1,370
  • 2
  • 18
  • 28