0

Please note I haven't attempted testing this yet, I'm simply preparing to research it more.

I'm creating an address book application, and want to do as follows:

  1. User clicks on a persons name in a list.
  2. A new tab opens with editable JTextField / JTextArea / etc.
  3. User saves / closes tab.

From looking at tutorials on Google, it has been suggested to have a method such as:

public void createPage1()
{
    panel1 = new JPanel();
    panel1.setLayout(new BorderLayout());

    panel1.add(new JButton("North"), BorderLayout.NORTH);
    panel1.add(new JButton("South"), BorderLayout.SOUTH);
    panel1.add(new JButton("East"), BorderLayout.EAST);
    panel1.add(new JButton("West"), BorderLayout.WEST);
    panel1.add(new JButton("Center"), BorderLayout.CENTER);
}

There were several of these methods, each creating one tab.

However, my program would allow it to be possible to have an unknown number of tabs open at the same time, all of which contain the exact same components in the same order. This obviously makes another alternative to the one above preferable.

How can this be accomplished?

Aaron
  • 992
  • 3
  • 15
  • 33
  • You are not using JTabbedPane? Post some valid code and read oracle tutorials – nachokk Sep 02 '13 at 23:02
  • @nachokk Thank you for taking the time to actually read my question. – Aaron Sep 02 '13 at 23:11
  • @Aaron You talk about "tabs", but don't mention exactly how you intend to accomplish it. With `JTabbedPane` you would simply continue adding views to the `JTabbedPane`, each view would be a self contained container containing all the required components you need for that tab – MadProgrammer Sep 02 '13 at 23:53
  • it's unclear what you are asking – nachokk Sep 03 '13 at 00:00

1 Answers1

2

In your ListSelectionListener, create and add() your new panel. In this complete example, a new panel in added in the Add button's ActionListener. Your createPane() method would need the parameters required to fill out a single address card.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • [`TabComponentsDemo`](http://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html) shows how to add close buttons. – trashgod Sep 03 '13 at 01:53