Jackmagic1
Jackmagic1

Reputation: 83

Dynamically adding tabs to JTabbedPane

In my main I loop over each League as below:

for (League l : t.getLeagues()) {
    LeaguePanel leaguePanel = new LeaguePanel(l);
    roundTabs.addTab(l.getName(), leaguePanel);
}

This should then create a JPanel and add it to the tab.

public class LeaguePanel extends JPanel {

    private League league;
    private JComboBox roundComboBox;

    LeaguePanel(League l) {
        league = l;
        JPanel leagePanel = new JPanel();
        leagePanel.add(new JLabel("Tournament Information"));
    }

However, the tab gets created but nothing appears within it

Any ideas why?

Upvotes: 1

Views: 1375

Answers (1)

Arnaud
Arnaud

Reputation: 17524

You want to add things to your LeaguePanel object, not to a new JPanel :

JPanel leagePanel = new JPanel();
leagePanel.add(new JLabel("Tournament Information"));

becomes

this.add(new JLabel("Tournament Information"));

Because it's your LeaguePanel that you add to the tabbed pane .

Upvotes: 4

Related Questions