I have a JTabbedPane
with 5 tabs in it. I also got 3 other buttons in same JFrame
where my JTabbedPane is added. I want to make the user able move to particular tab when a particular button is clicked. Here is the image example
Now for example if user clicks Button 1
then tab One
should be opened and similarly when button 2
is clicked then tab Two
should be opened and so for third one.
Here is my code to add these JTabbedPane and buttons.
public class TabsAndButtons
{
public TabsAndButtons()
{
JTabbedPane tabsPane = new JTabbedPane();
tabsPane.add("One", new JPanel());
tabsPane.add("Two", new JPanel());
tabsPane.add("Three", new JPanel());
tabsPane.add("Four", new JPanel());
tabsPane.add("Five", new JPanel());
JPanel Panel = new JPanel();
Panel.add(tabsPane);
JButton Button1 = new JButton("Button 1");
Panel.add(Button1);
JButton Button2 = new JButton("Button 2");
Panel.add(Button2);
JButton Button3 = new JButton("Button 3");
Panel.add(Button3);
JFrame MainFrame = new JFrame("JTabbedPane and Buttons");
MainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MainFrame.getContentPane().add(Panel );
MainFrame.pack();
MainFrame.setVisible(true);
}
public static void main(String[] args)
{
java.awt.EventQueue.invokeLater(() -> {
new TabsAndButtons();
});
}
}
The actual purpose of such action is very lengthy and has a lot details which will make the question dull so I am asking the main task where I stucked. Thanks for your kind support and time.