1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
public class OngletsEnGrasQdSelection extends JTabbedPane {
private static final long serialVersionUID = -8459114398874748745L;
public OngletsEnGrasQdSelection () {
super();
this.addChangeListener(new ChangerOngletListener());
}
public void add(Component comp, String title) {
if (this.getComponentCount() == 0) {
title = ChangerOngletListener.DEBUT + title + ChangerOngletListener.FIN;
}
super.add(comp, title);
}
/***************************************************
* LISTENERS
****************************************************/
private class ChangerOngletListener implements ChangeListener {
private int indexEnGras = 0;
private int nombreOnglet;
public final static String DEBUT = "<html><b>";
public final static String FIN = "</b></html>";
public void stateChanged(ChangeEvent e) {
JTabbedPane onglets = (JTabbedPane)e.getSource();
//Récupération du nombre d'onglet
nombreOnglet = onglets.getTabCount();
//Récupération de l'onglet sélectionné
indexEnGras = onglets.getSelectedIndex();
//On passe tous les onglets en font normal sauf celui sélectionné que l'on passe en gras
for (int i=0;i<nombreOnglet;i++){
String titre = onglets.getTitleAt(i);
if (i != indexEnGras){
if (titre.startsWith(DEBUT)) {
onglets.setTitleAt(i,titre.substring(DEBUT.length(), titre.length()-FIN.length()));
}
}
else
onglets.setTitleAt(i,DEBUT + titre.length() + FIN);
}
}
}
} |
Partager