Bonjour a tous.
J'ai crée une classe pour mon application qui définit les états d'un JTextPane selon des résultats de recherche.
Mais je voudrais ajouter une petite image a coté du texte.
Voici mon code:
Je vous remercie si vous pouvez mes donner des idées.
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 package dr.fidei.componentes; import java.awt.Color; import javax.swing.JTextPane; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; import dr.fidei.componentes.EstadoInfoPanel; /** * <b>InfoPanel es la clase que define un panel de información para mostrar resultados de búsqueda</b> * * @author A. Cedano * @version 1.0 * @date 30-12-2013 */ public class InfoPanel extends JTextPane { private static final long serialVersionUID = -2442636898173029903L; /** * @param texto * @param estado */ public InfoPanel(String texto, EstadoInfoPanel estado) { setEditable(false); setEtat(estado); setText(texto); StyledDocument doc = this.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false); } public void setEtat(EstadoInfoPanel estado){ switch (estado) { case NEUTRO: setOpaque(false); break; case ERROR: setOpaque(true); setBackground(new Color(232, 117, 140)); //J'essaie avec "insertIcon" sans success // insertIcon(new ImageIcon(InfoPanel.class.getResource("/dr/fidei/iconos/find32x32.png"))); break; case VALIDO: setOpaque(true); setBackground(new Color(168, 220, 120)); break; case SINDATOS: setOpaque(true); setBackground(new Color(255, 215, 0)); break; } } }
Partager