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
| public class JTabbedPaneExemple extends JPanel {
public static void main(String[] args) {
JTabbedPane pane = new JTabbedPane();
pane.add(new Component(Color.RED, "Onglet"), "Mon onglet", 0);
pane.setTabComponentAt(0,new ComponentTab(Color.YELLOW, "Etiquette"));
System.out.println(pane.getComponentAt(0)); // affiche class miseEnFormeDonneesCSV.JTabbedPaneExemple$Component
System.out.println(pane.getTabComponentAt(0)); // affiche class miseEnFormeDonneesCSV.JTabbedPaneExemple$ComponentTab
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(pane);
frame.setSize(300, 300);
frame.setVisible(true);
}
public static class Component extends JPanel {
public Component(Color bg, String text) {
super(new BorderLayout());
setBackground(bg);
add(new JLabel(text, JLabel.CENTER));
}
@Override
public String toString() {
return getClass().toString();
}
}
public static class ComponentTab extends Component {
public ComponentTab(Color bg, String text) {
super(bg,text);
}
}
} |
Partager