List of usage examples for java.awt Container add
public Component add(Component comp)
From source file:AbsoluteLayoutDemo.java
public static void addComponentsToPane(Container pane) { pane.setLayout(null);// w w w. j av a 2 s . c o m JButton b1 = new JButton("one"); JButton b2 = new JButton("two"); JButton b3 = new JButton("three"); pane.add(b1); pane.add(b2); pane.add(b3); Insets insets = pane.getInsets(); Dimension size = b1.getPreferredSize(); b1.setBounds(25 + insets.left, 5 + insets.top, size.width, size.height); size = b2.getPreferredSize(); b2.setBounds(55 + insets.left, 40 + insets.top, size.width, size.height); size = b3.getPreferredSize(); b3.setBounds(150 + insets.left, 15 + insets.top, size.width + 50, size.height + 20); }
From source file:SquareLayout.java
/** * Creates a new Container with SquareLayout which will contain the specified * component./*from www.j a v a 2 s. co m*/ */ public static Container createSquareContainer(Component child) { Container container = new Container(); container.setLayout(new SquareLayout()); container.add(child); return container; }
From source file:Main.java
public static void addComponentsToPane(Container pane) { pane.setLayout(new DiagonalLayout()); pane.add(new JButton("Button 1")); pane.add(new JButton("Button 2")); pane.add(new JButton("Button 3")); pane.add(new JButton("Button 4")); pane.add(new JButton("Button 5")); }
From source file:components.GlassPaneDemo.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.//from ww w. j av a2 s.co m */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("GlassPaneDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Start creating and adding components. JCheckBox changeButton = new JCheckBox("Glass pane \"visible\""); changeButton.setSelected(false); //Set up the content pane, where the "main GUI" lives. Container contentPane = frame.getContentPane(); contentPane.setLayout(new FlowLayout()); contentPane.add(changeButton); contentPane.add(new JButton("Button 1")); contentPane.add(new JButton("Button 2")); //Set up the menu bar, which appears above the content pane. JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("Menu"); menu.add(new JMenuItem("Do nothing")); menuBar.add(menu); frame.setJMenuBar(menuBar); //Set up the glass pane, which appears over both menu bar //and content pane and is an item listener on the change //button. myGlassPane = new MyGlassPane(changeButton, menuBar, frame.getContentPane()); changeButton.addItemListener(myGlassPane); frame.setGlassPane(myGlassPane); //Show the window. frame.pack(); frame.setVisible(true); }
From source file:GlassPaneDemo.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *//* ww w .jav a 2 s . co m*/ private static void createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("GlassPaneDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Start creating and adding components. JCheckBox changeButton = new JCheckBox("Glass pane \"visible\""); changeButton.setSelected(false); // Set up the content pane, where the "main GUI" lives. Container contentPane = frame.getContentPane(); contentPane.setLayout(new FlowLayout()); contentPane.add(changeButton); contentPane.add(new JButton("Button 1")); contentPane.add(new JButton("Button 2")); // Set up the menu bar, which appears above the content pane. JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("Menu"); menu.add(new JMenuItem("Do nothing")); menuBar.add(menu); frame.setJMenuBar(menuBar); // Set up the glass pane, which appears over both menu bar // and content pane and is an item listener on the change // button. myGlassPane = new MyGlassPane(changeButton, menuBar, frame.getContentPane()); changeButton.addItemListener(myGlassPane); frame.setGlassPane(myGlassPane); // Show the window. frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void addGridBagComponent(Container container, GridBagLayout gridbag, GridBagConstraints c, Component com, int gridx, int gridy, int gridwidth, int gridheight) { c.gridx = gridx;//w ww .j a va 2 s . c o m c.gridy = gridy; c.gridwidth = gridwidth; c.gridheight = gridheight; gridbag.setConstraints(com, c); container.add(com); }
From source file:SpringBox.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from w w w . j a v a2s . com*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("SpringBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); contentPane.setLayout(new SpringLayout()); //Add the buttons. contentPane.add(new JButton("Button 1")); contentPane.add(new JButton("Button 2")); contentPane.add(new JButton("Button 3")); contentPane.add(new JButton("Long-Named Button 4")); contentPane.add(new JButton("5")); //Lay out the buttons in one row and as many columns //as necessary, with 6 pixels of padding all around. SpringUtilities.makeCompactGrid(contentPane, 1, contentPane.getComponentCount(), 6, 6, 6, 6); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:layout.SpringDemo2.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread.//from w ww . j a v a2 s . c o m */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("SpringDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); //Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); //Adjust constraints for the label so it's at (5,5). layout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, contentPane); layout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, contentPane); //Adjust constraints for the text field so it's at //(<label's right edge> + 5, 5). layout.putConstraint(SpringLayout.WEST, textField, 5, SpringLayout.EAST, label); layout.putConstraint(SpringLayout.NORTH, textField, 5, SpringLayout.NORTH, contentPane); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:Main.java
/** * @param gx//ww w.ja va 2s .c om * @param gy * @param gw * @param gh * @param wx * @param wy * @param what * @param where * @param gbc * @param gridbag */ public static void add(int gx, int gy, int gw, int gh, int wx, int wy, Component what, Container where, GridBagConstraints gbc, GridBagLayout gridbag) { gbc.gridx = gx; gbc.gridy = gy; gbc.gridwidth = gw; gbc.gridheight = gh; gbc.weightx = wx; gbc.weighty = wy; gridbag.setConstraints(what, gbc); where.add(what); }
From source file:SpringDemo2.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *//*from w w w . j a v a2 s . c o m*/ private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("SpringDemo2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set up the content pane. Container contentPane = frame.getContentPane(); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); //Create and add the components. JLabel label = new JLabel("Label: "); JTextField textField = new JTextField("Text field", 15); contentPane.add(label); contentPane.add(textField); //Adjust constraints for the label so it's at (5,5). layout.putConstraint(SpringLayout.WEST, label, 5, SpringLayout.WEST, contentPane); layout.putConstraint(SpringLayout.NORTH, label, 5, SpringLayout.NORTH, contentPane); //Adjust constraints for the text field so it's at //(<label's right edge> + 5, 5). layout.putConstraint(SpringLayout.WEST, textField, 5, SpringLayout.EAST, label); layout.putConstraint(SpringLayout.NORTH, textField, 5, SpringLayout.NORTH, contentPane); //Display the window. frame.pack(); frame.setVisible(true); }