2

I have 2 JFrames:

  • first frame has a 3 JButtons: #1 #2 #3
  • second frame has a JTabbedPane with 3 tabs, each with a JPanel

When I press one of the buttons from first frame I want to open the second frame and focus on the corresponding tab in JTabbedPane (button #1 -> tab #1, button #2 -> tab #2, etc)

JButton btnNewButton = new JButton("Modifica");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                FirmaDateModifica frame = new FirmaDateModifica();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
                // Is there something I can do here?
            }
        });
Hugues M.
  • 19,846
  • 6
  • 37
  • 65
  • 1
    Read [this](https://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-or-bad-practice) first. – Blasanka Jun 11 '17 at 12:45

1 Answers1

0

I would recommend having a public method in FirmaDateModifica that takes an integer parameter as the tab index and then changes that currently selected tab in that frame. You should add an action listener to each of the three buttons and then use the different tab indexes as the parameters when calling the function that changes the tab in the second frame.