Java Tutorial/Swing/JSeparator

Материал из Java эксперт
Перейти к: навигация, поиск

Add Separator to Menu

   <source lang="java">

import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class JMenuwithSeparator {

 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);
 }

}</source>





Customizing JSeparator Look and Feel

Property StringObject TypeSeparator.backgroundColorSeparator.foregroundColorSeparator.insetsInsetsSeparator.thicknessIntegerSeparatorUIString


JSeparator

  1. The JSeparator class is a special component that acts as a separator on a JMenu.
  2. JSeparator can be used anywhere you want to use a horizontal or vertical line to separate different areas of a screen.


The JSeparator class provides a horizontal or vertical dividing line or empty space

   <source lang="java">

import javax.swing.JFrame; import javax.swing.JSeparator; public class JSeparatorVERTICALHORI {

 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);
 }

}</source>