Bonjour,
"avec UIManager.put"
Si tu fais ça, tu vas changer le comportement de toute la fenêtre pour tous les composants, tu ne vas pas pouvoir préciser l'utilisation uniquement pour ce composant uniquement.
Le plus propre serait d'utiliser JOptionPane.showOptionDialog qui permet de customiser le composant à afficher afin d'y mettre un JTextField avec une police modifiée.
Exemple :
import java.awt.*;
import javax.swing.*;
public static String showInputDialog(Component parentComponent, String message, String title, int messageType, Icon icon, float fontSize) {
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel(message), BorderLayout.NORTH);
JTextField field = new JTextField();
field.setFont(field.getFont().deriveFont(fontSize));
panel.add(field, BorderLayout.SOUTH);
int n = JOptionPane.showOptionDialog(parentComponent, panel, title, JOptionPane.OK_CANCEL_OPTION, messageType, icon, null, null);
return (n == JOptionPane.OK_OPTION) ? field.getText() : null;
}
Petit code de test pour comparer les deux InputDialog :
public static void main(String[] args) {
Component parentComponent = null;
String message = "Entrez un mot";
String title = "Choix";
int messageType = JOptionPane.QUESTION_MESSAGE;
Icon icon = null;
float fontSize = 15;
String text1 = (String) JOptionPane.showInputDialog(parentComponent, message, title, messageType, icon, null, null);
System.out.println(text1);
String text2 = showInputDialog(parentComponent, message, title, messageType, icon, fontSize);
System.out.println(text2);
}
12 nov. 2017 à 14:24
12 nov. 2017 à 15:01
12 nov. 2017 à 19:50
16 nov. 2017 à 17:18
16 nov. 2017 à 17:33