List of usage examples for java.awt Container add
public Component add(Component comp)
From source file:layout.SpringDemo3.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from w ww . ja va 2 s.c o m*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("SpringDemo3"); 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); //Adjust constraints for the content pane: Its right //edge should be 5 pixels beyond the text field's right //edge, and its bottom edge should be 5 pixels beyond //the bottom edge of the tallest component (which we'll //assume is textField). layout.putConstraint(SpringLayout.EAST, contentPane, 5, SpringLayout.EAST, textField); layout.putConstraint(SpringLayout.SOUTH, contentPane, 5, SpringLayout.SOUTH, textField); //Display the window. frame.pack(); frame.setVisible(true); }
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 .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("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:SpringDemo3.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. */// w w w . j a va 2 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("SpringDemo3"); 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); //Adjust constraints for the content pane: Its right //edge should be 5 pixels beyond the text field's right //edge, and its bottom edge should be 5 pixels beyond //the bottom edge of the tallest component (which we'll //assume is textField). layout.putConstraint(SpringLayout.EAST, contentPane, 5, SpringLayout.EAST, textField); layout.putConstraint(SpringLayout.SOUTH, contentPane, 5, SpringLayout.SOUTH, textField); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:layout.SpringDemo4.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 av a 2s . co m*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("SpringDemo4"); 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). SpringLayout.Constraints labelCons = layout.getConstraints(label); labelCons.setX(Spring.constant(5)); labelCons.setY(Spring.constant(5)); //Adjust constraints for the text field so it's at //(<label's right edge> + 5, 5). SpringLayout.Constraints textFieldCons = layout.getConstraints(textField); textFieldCons.setX(Spring.sum(Spring.constant(5), labelCons.getConstraint(SpringLayout.EAST))); textFieldCons.setY(Spring.constant(5)); //Adjust constraints for the content pane. setContainerSize(contentPane, 5); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:SpringDemo4.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *//*w w w . java2 s. co 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("SpringDemo4"); 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). SpringLayout.Constraints labelCons = layout.getConstraints(label); labelCons.setX(Spring.constant(5)); labelCons.setY(Spring.constant(5)); //Adjust constraints for the text field so it's at //(<label's right edge> + 5, 5). SpringLayout.Constraints textFieldCons = layout.getConstraints(textField); textFieldCons.setX(Spring.sum(Spring.constant(5), labelCons.getConstraint(SpringLayout.EAST))); textFieldCons.setY(Spring.constant(5)); //Adjust constraints for the content pane. setContainerSize(contentPane, 5); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:Main.java
static void addComponent(final Container cont, final GridBagLayout gbl, final Component c, final int x, final int y, final int width, final int height, final double weightx, final double weighty, int fill) { final GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = fill;//GridBagConstraints.BOTH; gbc.gridx = x;// w w w . java2 s . co m gbc.gridy = y; gbc.gridwidth = width; gbc.gridheight = height; gbc.weightx = weightx; gbc.weighty = weighty; gbl.setConstraints(c, gbc); cont.add(c); }
From source file:Main.java
/** * Puts the grid constraints for a component. * /*from w w w . ja v a2s .com*/ * @param container * The container to add the component to. * @param component * The component to create the constraints for. * @param gridX * The initial gridx value. * @param gridY * The initial gridy value. * @param gridWidth * The initial gridwidth value. * @param gridHeight * The initial gridheight value. * @param weightX * The initial weightx value. * @param weightY * The initial weighty value. * @param anchor * The initial anchor value. * @param fill * The initial fill value. */ public static final void noInsetsPutGrid(final Container container, final Component component, final int gridX, final int gridY, final int gridWidth, final int gridHeight, final double weightX, final double weightY, final int anchor, final int fill) { LayoutManager l; l = container.getLayout(); if (l instanceof GridBagLayout) { ((GridBagLayout) (l)).setConstraints(component, new GridBagConstraints(gridX, gridY, gridWidth, gridHeight, weightX, weightY, anchor, fill, NOINSETS, DEFAULT_IPAD_X, DEFAULT_IPAD_Y)); } container.add(component); }
From source file:Main.java
public static void addComponentToGridBagLayout(Container cont, GridBagLayout gbl, int x, int y, int width, int height, double weightx, double weighty, Component component) { GridBagConstraints gbc = new GridBagConstraints(); if (y == 0)/* w w w.ja v a2 s . c o m*/ gbc.insets = new Insets(8, 6, 4, 6); else gbc.insets = new Insets(4, 6, 4, 6); gbc.fill = GridBagConstraints.BOTH; gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = width; gbc.gridheight = height; gbc.weightx = weightx; gbc.weighty = weighty; gbl.setConstraints(component, gbc); cont.add(component); }
From source file:Main.java
public static void addComponent(final Container container, final GridBagLayout gbl, final Component c, final int x, final int y, final int width, final int height, final double weightx, final double weighty, final int anchor, final int fill, final Insets insets) { final GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = fill;/* www . j a v a2 s.co m*/ gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = width; gbc.gridheight = height; gbc.weightx = weightx; gbc.weighty = weighty; gbc.anchor = anchor; gbc.insets = insets; gbl.setConstraints(c, gbc); container.add(c); }
From source file:Main.java
/** * Puts the grid constraints for a component. * /*w ww . j a va 2 s . c o m*/ * @param container * The container to add the component to. * @param component * The component to create the constraints for. * @param gridX * The initial gridx value. * @param gridY * The initial gridy value. * @param gridWidth * The initial gridwidth value. * @param gridHeight * The initial gridheight value. * @param weightX * The initial weightx value. * @param weightY * The initial weighty value. * @param anchor * The initial anchor value. * @param fill * The initial fill value. * @param insets * The insets to be used. */ public static final void insetPutGrid(final Container container, final Component component, final int gridX, final int gridY, final int gridWidth, final int gridHeight, final double weightX, final double weightY, final int anchor, final int fill, final Insets insets) { LayoutManager l; l = container.getLayout(); if (l instanceof GridBagLayout) { ((GridBagLayout) (l)).setConstraints(component, new GridBagConstraints(gridX, gridY, gridWidth, gridHeight, weightX, weightY, anchor, fill, insets, DEFAULT_IPAD_X, DEFAULT_IPAD_Y)); } container.add(component); }