CsButtonGroup.java
2.97 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
package cn.csbr.app.gui.util;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import java.util.List;
public class CsButtonGroup {
public static Button createSingleButton(String text,String imgUrl) {
Button button = new Button(text);
if (imgUrl != null) {
ImageView imageView = new ImageView(imgUrl);
button = new Button(text, imageView);
button.setGraphicTextGap(15);//设置文字个icon的间距
}
button.setStyle("-fx-background-color: white;-fx-border-radius: 6;-fx-border-color: #bababa");;
return button;
}
public static Button createSingleButton(String text,String imgUrl,EventHandler<ActionEvent> handler) {
Button button = new Button(text);
if (imgUrl != null) {
ImageView imageView = new ImageView(imgUrl);
button = new Button(text, imageView);
button.setGraphicTextGap(15);//设置文字个icon的间距
}
if (handler != null) {
button.setOnAction(handler);
}
button.getStyleClass().add("singleBtn");
return button;
}
/**
* 使用样例
* Button btn1 = CsButtonGroup.createButton("损溢确认", "icon/icon_code.png");
* Button btn2 = CsButtonGroup.createButton("手动录入", "icon/icon_hadd.png");
* Button btn3 = CsButtonGroup.createButton("返回", "icon/icon_hadd.png");
* ArrayList<Button> buttons = Lists.newArrayList(btn1, btn2, btn3);
* HBox groupButton = CsButtonGroup.createGroupButton(buttons);
* @param text
* @param imgUrl
* @return
*/
public static Button createButton(String text,String imgUrl) {
return createButton(text,imgUrl,null);
}
public static Button createButton(String text,String imgUrl,EventHandler<ActionEvent> handler) {
Button button = new Button(text);
if (imgUrl != null) {
ImageView imageView = new ImageView(imgUrl);
button = new Button(text, imageView);
button.setGraphicTextGap(15);//设置文字个icon的间距
}
if (handler != null) {
button.setOnAction(handler);
}
button.setStyle("-fx-border-color:#d4d4d4;-fx-border-width:1;-fx-background-color: white;" +
"-fx-border-radius: 5");
return button;
}
public static HBox createGroupButton(List<Button> buttonList) {
HBox hb = new HBox();
hb.setAlignment(Pos.CENTER);
hb.getStyleClass().add("groupBtnBox");
int last = buttonList.size() - 1;
for (int i = 0; i < buttonList.size(); i++) {
hb.getChildren().add(buttonList.get(i));
if (i < last) {
Label label = new Label("|");
hb.getChildren().add(label);
}
}
return hb;
}
}