Java 中 JSeparator 類的重要性是什麼?
JSeparator
- JSeparator 是水平或垂直的線或分隔元件的空白。
- JSeparator 類用於在佈局中繪製一條線以分隔元件。
- 向選單或工具欄新增分隔符最簡單的方法是呼叫JMenu、JPopupMenu 和 JToolBar 類提供的 addSeparator() 方法。
- 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();
}
}輸出
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP