-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStyledComponents.java
More file actions
131 lines (113 loc) · 4.54 KB
/
Copy pathStyledComponents.java
File metadata and controls
131 lines (113 loc) · 4.54 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package banking;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
public class StyledComponents {
/**
* Create a styled button with custom colors
*/
public static JButton createStyledButton(String text, Color bgColor, Color fgColor, int width, int height) {
JButton button = new JButton(text);
button.setFont(new Font("Segoe UI", Font.BOLD, 16));
button.setPreferredSize(new Dimension(width, height));
button.setBackground(bgColor);
button.setForeground(fgColor);
button.setFocusPainted(false);
button.setBorderPainted(false);
button.setOpaque(true);
button.setCursor(new Cursor(Cursor.HAND_CURSOR));
// Rounded border effect
button.setBorder(new EmptyBorder(10, 25, 10, 25));
// Hover effect
button.addMouseListener(new java.awt.event.MouseAdapter() {
Color originalColor = bgColor;
public void mouseEntered(java.awt.event.MouseEvent evt) {
button.setBackground(bgColor.brighter());
}
public void mouseExited(java.awt.event.MouseEvent evt) {
button.setBackground(originalColor);
}
});
return button;
}
/**
* Create a styled text field
*/
public static JTextField createStyledTextField(int columns) {
JTextField field = new JTextField(columns);
field.setFont(new Font("Segoe UI", Font.PLAIN, 16));
field.setPreferredSize(new Dimension(300, 40));
field.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(189, 195, 199), 2),
BorderFactory.createEmptyBorder(5, 10, 5, 10)
));
return field;
}
/**
* Create a styled password field
*/
public static JPasswordField createStyledPasswordField(int columns) {
JPasswordField field = new JPasswordField(columns);
field.setFont(new Font("Segoe UI", Font.PLAIN, 16));
field.setPreferredSize(new Dimension(300, 40));
field.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(189, 195, 199), 2),
BorderFactory.createEmptyBorder(5, 10, 5, 10)
));
return field;
}
/**
* Create a styled label
*/
public static JLabel createStyledLabel(String text, int size, int style) {
JLabel label = new JLabel(text);
label.setFont(new Font("Segoe UI", style, size));
return label;
}
/**
* Create a panel with gradient background
*/
public static JPanel createGradientPanel(Color color1, Color color2) {
return new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
int w = getWidth();
int h = getHeight();
GradientPaint gp = new GradientPaint(0, 0, color1, 0, h, color2);
g2d.setPaint(gp);
g2d.fillRect(0, 0, w, h);
}
};
}
/**
* Create a card-style button for dashboard
*/
public static JButton createCardButton(String title, String subtitle, Color bgColor) {
JButton card = new JButton("<html><div style='text-align: center;'>" +
"<b style='font-size: 18px;'>" + title + "</b><br>" +
"<span style='font-size: 12px;'>" + subtitle + "</span>" +
"</div></html>");
card.setPreferredSize(new Dimension(250, 120));
card.setBackground(bgColor);
card.setForeground(Color.WHITE);
card.setFocusPainted(false);
card.setBorderPainted(false);
card.setOpaque(true);
card.setCursor(new Cursor(Cursor.HAND_CURSOR));
card.setFont(new Font("Segoe UI", Font.PLAIN, 14));
// Hover effect
card.addMouseListener(new java.awt.event.MouseAdapter() {
Color originalColor = bgColor;
public void mouseEntered(java.awt.event.MouseEvent evt) {
card.setBackground(bgColor.brighter());
}
public void mouseExited(java.awt.event.MouseEvent evt) {
card.setBackground(originalColor);
}
});
return card;
}
}