Bộ phân tách JS
- Một Bộ phân tách JS là ngang hoặc dọc dòng hoặc không gian trống phân tách các thành phần.
- Một Bộ phân tách JS lớp được sử dụng để vẽ một đường để phân tách các thành phần trong một bố cục.
- Cách dễ nhất để thêm dấu phân tách vào menu hoặc thanh công cụ là gọi addSeparator ( ) phương pháp do các lớp JMenu cung cấp , JPopupMenu và JToolBar .
- Các phương thức quan trọng của lớp JSeparator là setOrientation () và getOrientation ().
Ví dụ
import java.awt.*;
import javax.swing.*;
public class JSeparatorTest extends JFrame {
private JLabel label1, label2;
public JSeparatorTest() {
setTitle("JSeparator Test");
setLayout(new GridLayout(0, 1));
label1 = new JLabel("Above Separator");
add(label1);
JSeparator sep = new JSeparator();
add(sep); // add a separator between two labels.
label2 = new JLabel("Below Separator");
add(label2);
setSize(375, 250);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String args[]) {
new JSeparatorTest();
}
} Đầu ra