Java/Swing Components/Separator
Версия от 21:01, 31 мая 2010; (обсуждение)
A demonstration of the JSeparator() component used in a toolbar-like
<source lang="java">
// A quick demonstration of the JSeparator() component used in a toolbar-like container. import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSeparator; public class SeparatorExample extends JPanel {
public SeparatorExample() { super(true); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); Box box1 = new Box(BoxLayout.X_AXIS); Box box2 = new Box(BoxLayout.X_AXIS); Box box3 = new Box(BoxLayout.X_AXIS); box1.add(new JButton("Press Me")); box1.add(new JButton("No Me!")); box1.add(new JButton("Ignore Them!")); box2.add(new JSeparator()); box3.add(new JButton("I"m the Button!")); box3.add(new JButton("It"s me!")); box3.add(new JButton("Go Away!")); add(box1); add(box2); add(box3); } public static void main(String s[]) { SeparatorExample example = new SeparatorExample(); JFrame frame = new JFrame("Separator Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(example); frame.pack(); frame.setVisible(true); }
}
</source>
Separator Sample
<source lang="java">
import java.awt.BorderLayout; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JSeparator; public class SeparatorSample {
public static void main(String args[]) { JFrame frame = new JFrame("Separator Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSeparator north = new JSeparator(JSeparator.HORIZONTAL); JSeparator south = new JSeparator(JSeparator.VERTICAL); JSeparator east = new JSeparator(JSeparator.HORIZONTAL); JSeparator west = new JSeparator(JSeparator.VERTICAL); Container contentPane = frame.getContentPane(); contentPane.add(north, BorderLayout.NORTH); contentPane.add(south, BorderLayout.SOUTH); contentPane.add(east, BorderLayout.EAST); contentPane.add(west, BorderLayout.WEST); frame.setSize(350, 250); frame.setVisible(true); }
}
</source>
Separator Sample 2
<source lang="java">
import java.awt.Container; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JSeparator; public class AnotherSeparatorSample {
public static void main(String args[]) { JFrame f = new JFrame("JSeparator Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); content.setLayout(new GridLayout(0, 1)); JLabel above = new JLabel("Above Separator"); content.add(above); JSeparator separator = new JSeparator(); content.add(separator); JLabel below = new JLabel("Below Separator"); content.add(below); f.setSize(300, 100); f.setVisible(true); }
}
</source>