bonjour
je veux ajouter image à côté titre de l'onglet,mais après avoir exécution mon prg
image n'apparait pas à côté titre de l'onglet,veuillez m'aidez svp
mon image se trouve dans ce location:
C:\Users\xavier\workspace\Contenu\images\java1.ico
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 import java.awt.Color; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JTabbedPane; public class Fenetre extends JFrame { private JTabbedPane onglet; public Fenetre() { this.setLocationRelativeTo(null); this.setTitle("Gérer vos conteneur"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(200,200); Panneau[] tPan= { new Panneau(Color.RED),new Panneau(Color.GREEN),new Panneau(Color.BLUE) }; onglet=new JTabbedPane(); int i=0; for(Panneau pan:tPan) { onglet.add("Onglet N°"+(++i),pan); onglet.setIconAt((i-1),new ImageIcon("images/java1.ico")); } this.getContentPane().add(onglet); this.setVisible(true); } public static void main(String[] args) { Fenetre fen=new Fenetre(); } } import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import javax.swing.JPanel; public class Panneau extends JPanel { private Color color=Color.white; private static int COUNT=0; private String message=""; public Panneau() { } public Panneau(Color color) { this.color=color; this.message="Contenu du panneau N°"+(++COUNT); } public void paintComponent(Graphics g) { g.setColor(this.color); g.fillRect(0, 0, this.getWidth(),this.getHeight()); g.setColor(Color.white); g.setFont(new Font("Arial",Font.BOLD,15)); g.drawString(this.message,10,20); } }
Partager