Java Swing JSeparator

2018-01-09 19:23 更新

Java Swing教程 - Java Swing JSeparator


更改偵聽(tīng)器...

JSeparator經(jīng)常在菜單中使用以分離相關(guān)菜單項(xiàng)的組。

JSeparator經(jīng)常在菜單中使用以分離相關(guān)菜單項(xiàng)的組。...

以下代碼創(chuàng)建一個(gè)水平分隔符。默認(rèn)情況下,類型為水平。

JSeparator hs  = new JSeparator(); 

以下代碼創(chuàng)建一個(gè)水平分隔符。默認(rèn)情況下,類型為水平。...

JSeparator vs  = new JSeparator(SwingConstants.VERTICAL);

setOrientation()和getOrientation()方法來(lái)設(shè)置和獲取JSeparator的方向。

import javax.swing.JFrame;
import javax.swing.JSeparator;
//from   w w  w  . j  a  v  a  2  s.  c  o m
public class Main {

  public static void main(String[] a){
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


    frame.add(new JSeparator(JSeparator.VERTICAL));

    frame.setSize(300, 200);
    frame.setVisible(true);
  }


}


將分隔符添加到菜單

import java.awt.event.KeyEvent;
/*  w  w  w .  ja v a  2s .  c  o m*/
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class Main {

  public static void main(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);

    // File->New, N - Mnemonic
    JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N);
    fileMenu.add(newMenuItem);

    // Separator
    fileMenu.addSeparator();

    // File->Save, S - Mnemonic
    JMenuItem saveMenuItem = new JMenuItem("Save", KeyEvent.VK_S);
    fileMenu.add(saveMenuItem);

    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);
  }
}


將分隔符添加到菜單...

屬性字符串 對(duì)象類型
Separator.background Color
Separator.foreground Color
Separator.insets Insets
Separator.thickness Integer
SeparatorUI String
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)