JSeparator
- A JSeparator เป็น แนวนอน หรือ แนวตั้ง ไลน์ หรือที่ว่าง ที่แยกส่วนประกอบ
- A JSeparator คลาส ใช้เพื่อ ลากเส้นเพื่อแยกส่วนประกอบ ในเลย์เอาต์
- วิธีที่ง่ายที่สุดในการเพิ่มตัวคั่นในเมนูหรือแถบเครื่องมือคือการเรียก addSeparator( ) วิธีการ จัดให้โดยคลาส JMenu , JPopupMenu และ JToolBar .
- วิธีการที่สำคัญของคลาส JSeparator คือ setOrientation() และ getOrientation()
ตัวอย่าง
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();
}
} ผลลัพธ์
