-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoLayoutDemo.java
More file actions
28 lines (22 loc) · 788 Bytes
/
NoLayoutDemo.java
File metadata and controls
28 lines (22 loc) · 788 Bytes
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
import javax.swing.*;
public class NoLayoutDemo {
public static void main(String[] args) {
JFrame frame = new JFrame("No Layout (Absolute Positioning)");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420, 250);
// Disable layout manager
frame.setLayout(null);
JLabel label = new JLabel("Username:");
JTextField tf = new JTextField();
JButton btn = new JButton("Login");
// Manually set x, y, width, height
label.setBounds(30, 30, 100, 25);
tf.setBounds(120, 30, 200, 25);
btn.setBounds(120, 70, 100, 30);
frame.add(label);
frame.add(tf);
frame.add(btn);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}