2009-05-27 12 views

risposta

11

Aggiungi un listener di azione al pulsante che chiama setSelectedComponent, o setSelectedIndex sulla JTabbedPane.

1

Se il nome del tuo jtabbedpane è mytabbedpane va in questo modo:

mytabbedpane.getSelectedIndex(); 

che restituisce l'int di quella scheda (0,1 .. n) o

mytabbedpane.getSelectedComponent(); 

che restituisce la stringa del nome della scheda ("Scheda attiva", "Seconda scheda", ...).

Se si desidera utilizzare il "getSelectedComponent()" per la logica booleana si dovrebbe scrivere qualcosa di simile a:

if (mytabbedpane.getSelectedComponent().equals("First tab")) { 
    //code here 
} 

e per il "getSelectedIndex()" uno è naturalmente:

if (mytabbedpane.getSelectedIndex() == 0) { 
    //code here 
} 
+1

.getSelectedComponent() restituisce Componente, non String. – Arttu

0

Prova questo codice:

tabbedPane.addTab(tabName, component); 
int count = tabbedPane.getTabCount(); 
tabbedPane.setSelectedIndex(count-1); 
Problemi correlati