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