49 lines
2.0 KiB
Java
49 lines
2.0 KiB
Java
|
package fr.monkhanny.dorfromantik.components;
|
||
|
|
||
|
import fr.monkhanny.dorfromantik.utils.FontManager;
|
||
|
|
||
|
import javax.swing.*;
|
||
|
import java.awt.*;
|
||
|
|
||
|
public class Button {
|
||
|
|
||
|
public static JButton createCustomTextButton(String text, float fontSize) {
|
||
|
JButton button = new JButton(text);
|
||
|
button.setFocusPainted(false); // Retirer le focus
|
||
|
button.setBackground(new Color(102, 178, 255)); // Couleur de fond
|
||
|
button.setForeground(Color.WHITE); // Couleur du texte
|
||
|
button.setFont(FontManager.getButtonFont(fontSize)); // Appliquer la police du bouton
|
||
|
button.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); // Espacement autour du texte du bouton
|
||
|
return button;
|
||
|
}
|
||
|
|
||
|
public static JButton createCustomIconButton(String iconPath) {
|
||
|
// Créer le bouton
|
||
|
JButton button = new JButton();
|
||
|
button.setFocusPainted(false); // Retirer le focus
|
||
|
|
||
|
// Charger l'icône depuis le chemin spécifié
|
||
|
ImageIcon icon = new ImageIcon(iconPath);
|
||
|
|
||
|
// Calculer automatiquement la taille de l'icône pour l'adapter à la taille du bouton
|
||
|
int buttonWidth = 100; // Taille du bouton (largeur)
|
||
|
int buttonHeight = 100; // Taille du bouton (hauteur)
|
||
|
|
||
|
// Vous pouvez ajuster ces valeurs ou les calculer dynamiquement en fonction de la taille du bouton
|
||
|
Image img = icon.getImage();
|
||
|
Image resizedImage = img.getScaledInstance(buttonWidth, buttonHeight, Image.SCALE_SMOOTH);
|
||
|
button.setIcon(new ImageIcon(resizedImage));
|
||
|
|
||
|
// Optionnel : changer la couleur de fond ou de bordure si nécessaire
|
||
|
button.setBackground(new Color(102, 178, 255)); // Couleur de fond (facultatif)
|
||
|
|
||
|
// Retirer la bordure du bouton (facultatif)
|
||
|
button.setBorder(BorderFactory.createEmptyBorder());
|
||
|
|
||
|
// Redimensionner le bouton pour s'adapter à l'icône si nécessaire
|
||
|
button.setPreferredSize(new Dimension(buttonWidth, buttonHeight));
|
||
|
|
||
|
return button;
|
||
|
}
|
||
|
}
|