List of usage examples for java.awt Container add
public Component add(Component comp)
From source file:SpringSample.java
public static void main(String args[]) { JFrame frame = new JFrame("SpringLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout);//from ww w .j a v a2 s.c o m Component left = new JLabel("Left"); Component right = new JTextField(15); contentPane.add(left); contentPane.add(right); layout.putConstraint(SpringLayout.WEST, left, 10, SpringLayout.WEST, contentPane); layout.putConstraint(SpringLayout.NORTH, left, 25, SpringLayout.NORTH, contentPane); layout.putConstraint(SpringLayout.NORTH, right, 25, SpringLayout.NORTH, contentPane); layout.putConstraint(SpringLayout.WEST, right, 20, SpringLayout.EAST, left); frame.setSize(300, 100); frame.setVisible(true); }
From source file:RedBlueBox.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(0, 1)); JComponent comp = new RedBlueBox(); comp.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, Color.PINK)); contentPane.add(comp); comp = new RedBlueBox(); contentPane.add(comp);//from w ww . j a v a 2 s.c om frame.setSize(300, 200); frame.show(); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame("SpringLayout"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout);/*from w w w. ja v a 2s. c o m*/ Component left = new JLabel("Name"); Component right = new JTextField(15); contentPane.add(left); contentPane.add(right); layout.putConstraint(SpringLayout.WEST, left, 10, SpringLayout.WEST, contentPane); layout.putConstraint(SpringLayout.NORTH, left, 25, SpringLayout.NORTH, contentPane); layout.putConstraint(SpringLayout.NORTH, right, 25, SpringLayout.NORTH, contentPane); layout.putConstraint(SpringLayout.WEST, right, 20, SpringLayout.EAST, left); frame.setSize(300, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(0, 1)); ButtonGroup group = new ButtonGroup(); JRadioButton option = new JRadioButton("French Fries", true); group.add(option);/*from w ww. ja v a 2s . co m*/ contentPane.add(option); option = new JRadioButton("Onion Rings", false); group.add(option); contentPane.add(option); option = new JRadioButton("Ice Cream", false); group.add(option); contentPane.add(option); frame.setSize(200, 200); frame.show(); }
From source file:com.google.code.facebook.graph.sna.applet.ImageEdgeLabelDemo.java
/** * a driver for this demo// w w w . ja va 2s. c o m */ public static void main(String[] args) { JFrame frame = new JFrame(); Container content = frame.getContentPane(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); content.add(new ImageEdgeLabelDemo()); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JPanel panel = new JPanel(); Container c = frame.getContentPane(); panel.setSize(100, 100);//from w ww . jav a 2 s.c o m panel.setLayout(new GridLayout(1000, 1)); for (int i = 0; i < 1000; i++) panel.add(new JLabel("JLabel " + i)); JScrollPane jsp = new JScrollPane(panel); c.add(jsp); frame.setSize(100, 100); frame.setVisible(true); }
From source file:BorderSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border bevelBorder = new BevelBorder(BevelBorder.RAISED, Color.red, Color.red.darker(), Color.pink, Color.pink.brighter()); Border emptyBorder = new EmptyBorder(5, 10, 5, 10); Border etchedBorder = new EtchedBorder(EtchedBorder.RAISED, Color.red, Color.pink); Border lineBorder = new LineBorder(Color.red, 5); Icon diamondIcon = new DiamondIcon(Color.red); Border matteBorder = new MatteBorder(5, 10, 5, 10, diamondIcon); Border softBevelBorder = new SoftBevelBorder(BevelBorder.RAISED, Color.red, Color.red.darker(), Color.pink, Color.pink.brighter()); Font font = new Font("Serif", Font.ITALIC, 12); Border titledBorder = new TitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM, font, Color.red);//from ww w . j ava 2 s .c o m Border compoundBorder = new CompoundBorder(lineBorder, matteBorder); JLabel bevelLabel = new JLabel("Bevel"); bevelLabel.setBorder(bevelBorder); bevelLabel.setHorizontalAlignment(JLabel.CENTER); JLabel emptyLabel = new JLabel("Empty"); emptyLabel.setBorder(emptyBorder); emptyLabel.setHorizontalAlignment(JLabel.CENTER); JLabel etchedLabel = new JLabel("Etched"); etchedLabel.setBorder(etchedBorder); etchedLabel.setHorizontalAlignment(JLabel.CENTER); JLabel lineLabel = new JLabel("Line"); lineLabel.setBorder(lineBorder); lineLabel.setHorizontalAlignment(JLabel.CENTER); JLabel matteLabel = new JLabel("Matte"); matteLabel.setBorder(matteBorder); matteLabel.setHorizontalAlignment(JLabel.CENTER); JLabel softBevelLabel = new JLabel("Soft Bevel"); softBevelLabel.setBorder(softBevelBorder); softBevelLabel.setHorizontalAlignment(JLabel.CENTER); JLabel titledLabel = new JLabel("Titled"); titledLabel.setBorder(titledBorder); titledLabel.setHorizontalAlignment(JLabel.CENTER); JLabel compoundLabel = new JLabel("Compound"); compoundLabel.setBorder(compoundBorder); compoundLabel.setHorizontalAlignment(JLabel.CENTER); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(2, 4, 5, 5)); contentPane.add(bevelLabel); contentPane.add(emptyLabel); contentPane.add(etchedLabel); contentPane.add(lineLabel); contentPane.add(matteLabel); contentPane.add(softBevelLabel); contentPane.add(titledLabel); contentPane.add(compoundLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("SpringLayout2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); SpringLayout springLayout = new SpringLayout(); contentPane.setLayout(springLayout); JButton b1 = new JButton("Button 1"); JButton b2 = new JButton("Button Second"); contentPane.add(b1); contentPane.add(b2);/*from w ww. j a v a2 s . co m*/ springLayout.putConstraint(SpringLayout.WEST, b1, 10, SpringLayout.WEST, contentPane); springLayout.putConstraint(SpringLayout.NORTH, b1, 20, SpringLayout.NORTH, contentPane); springLayout.putConstraint(SpringLayout.WEST, b2, 10, SpringLayout.EAST, b1); springLayout.putConstraint(SpringLayout.NORTH, b2, 20, SpringLayout.NORTH, contentPane); springLayout.putConstraint(SpringLayout.SOUTH, contentPane, 10, SpringLayout.SOUTH, b1); springLayout.putConstraint(SpringLayout.EAST, contentPane, 10, SpringLayout.EAST, b2); frame.pack(); frame.setVisible(true); }
From source file:BoxLayoutYAXISTest.java
public static void main(String[] args) { JFrame f = new JFrame("Vertical BoxLayout-managed container"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = f.getContentPane(); pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); for (float align = 0.0f; align <= 1.0f; align += 0.25f) { JButton button = new JButton("X Alignment = " + align); button.setAlignmentX(align);// w w w . j a v a2s .co m pane.add(button); } f.setSize(400, 300); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) throws ParseException { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS)); MaskFormatter mf1 = new MaskFormatter("###-###-###"); mf1.setPlaceholderCharacter('_'); JFormattedTextField ftf1 = new JFormattedTextField(mf1); content.add(ftf1); MaskFormatter mf2 = new MaskFormatter("(###) ###-####"); JFormattedTextField ftf2 = new JFormattedTextField(mf2); content.add(ftf2);/*from ww w.j a va 2 s . c o m*/ f.setSize(300, 100); f.setVisible(true); }