-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamplez_cbutton.java
63 lines (46 loc) · 1.69 KB
/
examplez_cbutton.java
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
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingConstants;
import java.awt.Dimension;
import java.awt.EventQueue;
import static javax.swing.LayoutStyle.ComponentPlacement.RELATED;
public class GroupLayoutCornerButtonsEx extends JFrame {
public GroupLayoutCornerButtonsEx() {
initUI();
}
private void initUI() {
setPreferredSize(new Dimension(300, 200));
var cpane = getContentPane();
var gl = new GroupLayout(cpane);
cpane.setLayout(gl);
gl.setAutoCreateGaps(true);
gl.setAutoCreateContainerGaps(true);
var okButton = new JButton("OK");
var closeButton = new JButton("Close");
gl.setHorizontalGroup(gl.createSequentialGroup()
.addPreferredGap(RELATED,
GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(okButton)
.addComponent(closeButton)
);
gl.setVerticalGroup(gl.createSequentialGroup()
.addPreferredGap(RELATED,
GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(gl.createParallelGroup()
.addComponent(okButton)
.addComponent(closeButton))
);
gl.linkSize(SwingConstants.HORIZONTAL, okButton, closeButton);
pack();
setTitle("Buttons");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
var ex = new GroupLayoutCornerButtonsEx();
ex.setVisible(true);
});
}
}