Bonjour,
Est-il possible de modifier la police d'un JLabel ?
Je ne trouve pas la méthode pour...
Merci.
Version imprimable
Bonjour,
Est-il possible de modifier la police d'un JLabel ?
Je ne trouve pas la méthode pour...
Merci.
Un petit setFont (Font f) fera l'affaire, à toi de voire dans la javadoc comment utiliser la classe Font
Merci!
J'ai vu qu'on pouvait aussi mettre en forme avec la methode setFont.
Mais comment mettre en gras et en italique ?
J'ai essayé :
(Ca me mets uniquement en italique)Code:label.setFont(new Font ("Serif",Font.BOLD+Font.ITALIC,12));
essaye avec un |
Code:
1
2 label.setFont(new Font ("Serif",Font.BOLD | Font.ITALIC, 12));
Merci pour ta réponse.
Ca ne fonctionne pas non plus, ça reste en italique :?
bizzare...
chez moi ca marche.
on peux voir ton code complet?
Code:
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 import java.awt.FlowLayout; import java.awt.Font; import java.awt.HeadlessException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; /** * Created by IntelliJ IDEA. * User: bebe * Date: 11-Jun-2006 * Time: 16:10:29 * To change this template use File | Settings | File Templates. */ public class Test1 extends JFrame implements ActionListener { private JLabel myLabel = null; public Test1() throws HeadlessException { setLayout(new FlowLayout()); myLabel = new JLabel("Testing Bold and Italic"); JButton myButton = new JButton("Change font..."); myButton.addActionListener(this); add(myLabel); add(myButton); } public static void main(String[] args) { Test1 t1 = new Test1(); t1.pack(); t1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); t1.setLocationRelativeTo(null); t1.setVisible(true); } public void actionPerformed(ActionEvent e) { myLabel.setFont(new Font("Verdana", Font.BOLD | Font.ITALIC, 15)); //To change body of implemented methods use File | Settings | File Templates. } }
dit moi, tu travaille sous Windows?
le JLabel n'est pas par defaut en Bold?
teste ce code.
oublie le precedant:
3 labelCode:
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 import java.awt.GridBagLayout; import java.awt.HeadlessException; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.JFrame; import javax.swing.JLabel; /** * Created by IntelliJ IDEA. * User: bebe * Date: 11-Jun-2006 * Time: 16:10:29 * To change this template use File | Settings | File Templates. */ public class Test1 extends JFrame { private JLabel myLabel = null; public Test1() throws HeadlessException { setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.insets = new Insets(5,5,5,5); myLabel = new JLabel("Default JLabel"); Font myFont = myLabel.getFont(); myLabel.setFont(myFont.deriveFont(myFont.getStyle() ^ Font.BOLD)); add(myLabel, gbc); myLabel = new JLabel("Bold JLabel"); myFont = myLabel.getFont(); myLabel.setFont(myFont.deriveFont(myFont.getStyle() | Font.BOLD)); add(myLabel, gbc); myLabel = new JLabel("Bold and Italic JLabel"); myFont = myLabel.getFont(); myLabel.setFont(myFont.deriveFont(myFont.getStyle() | Font.ITALIC)); add(myLabel, gbc); } public static void main(String[] args) { Test1 t1 = new Test1(); t1.pack(); t1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); t1.setLocationRelativeTo(null); t1.setVisible(true); } }
un normal sans gras ni italic
un gras
et un gras et italic
En fait, j'ai essayé avec une taille de police plus grande et c'était ça!
Le gras n'est pas visible en dessous de 12, mais l'est à 13 ou au delà.
Merci de ton aide.