If I have a collection of objects:
public class Party {
LinkedList<Guy> partyList = new LinkedList<Guy>();
public void addGuy(Guy c) {
partyList.add(c);
}
}
And a tabbedPane:
public class CharWindow
{
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
try
{
CharWindow window = new CharWindow();
window.frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public CharWindow()
{
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize()
{
frame = new JFrame();
frame.setBounds(100, 100, 727, 549);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP);
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
JTabbedPane PartyScreen = new JTabbedPane(SwingConstants.TOP);
tabbedPane.addTab("Party Screen", null, PartyScreen, null);
JTabbedPane tabbedPane_2 = new JTabbedPane(SwingConstants.TOP);
tabbedPane.addTab("New tab", null, tabbedPane_2, null);
JTabbedPane tabbedPane_3 = new JTabbedPane(SwingConstants.TOP);
tabbedPane.addTab("New tab", null, tabbedPane_3, null);
}
}
How would I add content to the tabbedPane “Party Screen” such that it displays a JLabel “Name” and a vertical JSeparator for each item in my LinkedList?
First, JTabbedPane is the widget that creates a new tab for each element panel. It is not the child of a tabbed interface. (Eg. JTabbedPane should hold a JPanel called partyScreen.)
Remember, Java naming convention has a variable start with a lower case letter — so partyScreen is preferred to PartyScreen.
Then iterate through each
Guyobject inPartyand add the appropriate components. I have no idea why you’re using aLinkedListinstead of aList, but I’ll assume you have a good reason not included in the code above.Depending on how you want it to be arranged in the
partyScreenpanel, you’ll probably want to look into a Layout Manager.