Salut !
je suis a la recherche d'un API qui permet de faire ses propres infobulles , j'avait vu un api qui permettait de faire ca , mais impossible de le retrouver :/
Merci
Salut !
je suis a la recherche d'un API qui permet de faire ses propres infobulles , j'avait vu un api qui permettait de faire ca , mais impossible de le retrouver :/
Merci
quel genre de tooltip tu veut faire?
avec swing tu peut deja faire beaucoup. tu peux mettre des couleurs des image des composant aussi
comme il extend de JComponent tu peut presque tout faire.
qu'est ce que tu veut au juste?
je savait pas qu'on pouvais de base avec Swing ...Envoyé par bbclone
en gros je cherche une api ou une classe qui permet de faire facilement ses propres infobulles (comme msn par exemple)
ou comme le fait Azureus :
![]()
Euh pour moi ceci n'a rien à voir avec un infobulle, pour moi une infobulle c'est plutôt ceci:
Bon ensuite pour le genre de composants que tu cherches, au choix, soit en faisant joujou avec une JWindow(ou une JFrame avec un setDecorated(false), c'est la même chose) et du setPositionpour l'affichage progressif, si il y a besoin.
Sinon tu as forcément des projets qui t'ont déjà implémenté ça:
http://jtoaster.sourceforge.net/
http://staff.washington.edu/netghost/perkup/
Pour ce qui est des infobulles façon msn, tu peut aller voir là http://jtoaster.sourceforge.net/
info bulle pour moi ca veut tootip. non?
j'ai vite fais un petit code qui montre comment tu peux avoir tes tooltip comme tu veut![]()
![]()
tien teste ca tu vois que tu peux mettre tout ce que tu veux dans ton JTooltip.
le code est plutot simple a comprendre.
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 import javax.swing.JToolTip; /** * Created by IntelliJ IDEA. * User: bebe * Date: 09-Jun-2006 * Time: 09:38:09 * To change this template use File | Settings | File Templates. */ public class JMyOwnToolTip extends JToolTip { protected int columns = 0; protected int fixedwidth = 0; public JMyOwnToolTip() { updateUI(); } @Override public void updateUI() { setUI(MyOwnToolTipUI.createUI(this)); } public void setColumns(int columns) { this.columns = columns; this.fixedwidth = 0; } public int getColumns() { return columns; } public void setFixedWidth(int width) { this.fixedwidth = width; this.columns = 0; } public int getFixedWidth() { return fixedwidth; } }
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.CellRendererPane; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JToolTip; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicToolTipUI; /** * Created by IntelliJ IDEA. * User: bebe * Date: 09-Jun-2006 * Time: 09:39:19 * To change this template use File | Settings | File Templates. */ public class MyOwnToolTipUI extends BasicToolTipUI { static MyOwnToolTipUI sharedInstance = new MyOwnToolTipUI(); static JToolTip myTooltip; protected CellRendererPane myRendererPane; private static JPanel myPanel = null; public static ComponentUI createUI(JComponent c) { return sharedInstance; } public MyOwnToolTipUI() { super(); } @Override public void installUI(JComponent c) { super.installUI(c); myTooltip = (JToolTip) c; myRendererPane = new CellRendererPane(); c.add(myRendererPane); } @Override public void uninstallUI(JComponent c) { super.uninstallUI(c); c.remove(myRendererPane); myRendererPane = null; } @Override public void paint(Graphics g, JComponent c) { Dimension size = c.getSize(); myPanel.setBackground(Color.RED); myRendererPane.paintComponent(g, myPanel, c, 1, 1, size.width - 1, size.height - 1, true); } @Override public Dimension getPreferredSize(JComponent c) { String tipText = ((JToolTip) c).getTipText(); if (tipText == null) { return new Dimension(0, 0); } String[] tipTextParts = tipText.split(";"); myPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(10, 5, 10, 5); gbc.gridx = 0; gbc.gridy = GridBagConstraints.RELATIVE; gbc.fill = GridBagConstraints.HORIZONTAL; myPanel.add(new JScrollPane(new JTextArea(tipTextParts[0])), gbc); gbc.fill = GridBagConstraints.NONE; myPanel.add(new JLabel(tipTextParts[1]), gbc); myPanel.add(new JButton(tipTextParts[2]), gbc); myRendererPane.removeAll(); myRendererPane.add(myPanel); Dimension dimension = myPanel.getPreferredSize(); dimension.height += 1; dimension.width += 1; return dimension; } @Override public Dimension getMinimumSize(JComponent c) { return getPreferredSize(c); } @Override public Dimension getMaximumSize(JComponent c) { return getPreferredSize(c); } }pour changer les duree d'afichage
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 import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JToolTip; import javax.swing.ToolTipManager; /** * Created by IntelliJ IDEA. * User: bebe * Date: 09-Jun-2006 * Time: 09:38:46 * To change this template use File | Settings | File Templates. */ public class MyOwnTooltipTest { public static void main(String[] args) { JFrame f = new JFrame("Special tooltip demo..."); JButton button = new JButton("My Button with special tooltip") { public JToolTip createToolTip() { return new JMyOwnToolTip(); } }; button.setToolTipText("text for JTextArea....." + "\n" + "\n" + "\n;" + "text on the label;and now text on the button"); f.setLayout(new FlowLayout()); f.add(button); button = new JButton("a button with basic tooltip"); button.setToolTipText("A tooltip"); f.add(button); f.pack(); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } }
la duree apres combien de temps il doit s'afficher
comment reagir a la souris... utilise alors TooltipManager (javax.swing.TooltipManger)
Partager