2010-11-29 32 views
0

J'ai une Jframe déclarée et y ajoute un JTabbedPane.JFrame avec JTabbedPane & JButton

Il y a 4 onglets et chacun a un contenu de table.

Maintenant, je dois ajouter un bouton d'actualisation à chaque onglet, comment puis-je faire cela?

Voilà comment je fais:

frmSql = new JFrame(); 
JTabbedPane tabbedPane = new JTabbedPane(); 
tabbedPane.addTab("Events", retrieveData("events")); 

tabbedPane.addTab("Completed Events", retrieveData("completed")); 
frmSql.add(tabbedPane); 

Toutes les suggestions?

Répondre

1
static void createAndShowGui() { 
    JFrame frmSql = new JFrame(); 
    JTabbedPane tabbedPane = new JTabbedPane(); 
    Action refreshEvents = null, refreshCompletedEvents = null; 
    tabbedPane.addTab("Events", createTab(retrieveData("events"), refreshEvents)); 
    // more tabs 
    tabbedPane.addTab("Completed Events", createTab(retrieveData("completed"), refreshCompletedEvents)); 
    frmSql.setContentPane(tabbedPane); 

} 

static JComponent createTab(JComponent content, Action refreshAction) { 
    JPanel p = new JPanel(new BorderLayout()); 
    p.add(content, BorderLayout.CENTER); 
    JPanel btns = new JPanel(); 
    BoxLayout layout = new BoxLayout(btns, BoxLayout.LINE_AXIS); 
    btns.setLayout(layout); 
    JButton refreshBtn = new JButton(refreshAction); 
    btns.add(refreshBtn); 
    btns.add(Box.createHorizontalGlue()); 
    p.add(btns, BorderLayout.PAGE_END); 
    return p; 
} 

Bien sûr, si retriveData prend du temps, il ne devrait pas être appelé de EDT

+0

Mais l'onglet n'est pas Rechargement, comment puis-je faire cela? – Vivek