-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUI.java
More file actions
executable file
·51 lines (46 loc) · 1.35 KB
/
UI.java
File metadata and controls
executable file
·51 lines (46 loc) · 1.35 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
package net.runelite.client.plugins;
import javax.swing.*;
import java.awt.*;
import java.util.function.Consumer;
public class UI {
/**
* Hollow factory/decorator for JLabels
* @param actions
* @return
*/
@SafeVarargs
public static JPanel createJPanel(Consumer<JPanel>... actions) {
JPanel panel = new JPanel();
for(Consumer<JPanel> action: actions) {
action.accept(panel);
}
return panel;
}
/**
* Hollow factory/decorator for JLabels
* @param actions
* @return
*/
@SafeVarargs
public static JLabel createJLabel(Consumer<JLabel>... actions) {
JLabel label = new JLabel();
for(Consumer<JLabel> action: actions) {
action.accept(label);
}
return label;
}
public static void align(JPanel panel) {
for (Component component : panel.getComponents()) {
if (component instanceof JPanel) {
align((JPanel)component);
} else if (component instanceof JComponent) {
((JComponent)component).setAlignmentX(0.5f);
}
}
}
public static JPanel boxPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
return panel;
}
}