Example usage for java.awt Container getComponent

List of usage examples for java.awt Container getComponent

Introduction

In this page you can find the example usage for java.awt Container getComponent.

Prototype

public Component getComponent(int n) 

Source Link

Document

Gets the nth component in this container.

Usage

From source file:CircleOfSquares.java

public Dimension preferredLayoutSize(Container parent) {

    int rowCount = rows;
    int colCount = cols;
    Insets parentInsets = parent.insets();
    int componentCount = parent.countComponents();

    if (rowCount > 0) {
        colCount = (componentCount + rowCount - 1) / rowCount;
    } else {//from  w ww  .j  a v a  2s . com
        rowCount = (componentCount + colCount - 1) / colCount;
    }

    // Find the maximum preferred width and the maximum preferred height
    // of any component.
    int w = 0;
    int h = 0;
    for (int i = 0; i < componentCount; i++) {

        Component comp = parent.getComponent(i);
        Dimension d = comp.preferredSize();
        if (w < d.width) {
            w = d.width;
        }
        if (h < d.height) {
            h = d.height;
        }
    }

    // Return the maximum preferred component width and height times the number
    // of columns and rows, respectively, plus any insets in the parent.
    return new Dimension(parentInsets.left + parentInsets.right + colCount * w,
            parentInsets.top + parentInsets.bottom + rowCount * h);
}

From source file:CircleOfSquares.java

public Dimension minimumLayoutSize(Container parent) {

    Insets parentInsets = parent.insets();
    int componentCount = parent.countComponents();
    int rowCount = rows;
    int colCount = cols;

    if (rowCount > 0) {
        colCount = (componentCount + rowCount - 1) / rowCount;
    } else {/*from   w w w .  ja v  a2s.c  om*/
        rowCount = (componentCount + colCount - 1) / colCount;
    }

    // Find the maximum "minimum width" and the maximum "minimum height"
    // of any component.
    int w = 0;
    int h = 0;
    for (int i = 0; i < componentCount; i++) {

        Component comp = parent.getComponent(i);
        Dimension d = comp.minimumSize();
        if (w < d.width) {
            w = d.width;
        }
        if (h < d.height) {
            h = d.height;
        }
    }

    // Return the maximum "minimum component width and height" times the number
    // of columns and rows, respectively, plus any insets in the parent.
    return new Dimension(parentInsets.left + parentInsets.right + colCount * w,
            parentInsets.top + parentInsets.bottom + rowCount * h);
}

From source file:net.openbyte.gui.CreateProjectFrame.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - Gary Lee
    button1 = new JButton();
    textField1 = new JTextField();
    label1 = new JLabel();
    comboBox1 = new JComboBox<>();
    label2 = new JLabel();
    comboBox2 = new JComboBox<>();
    label3 = new JLabel();
    button2 = new JButton();

    //======== this ========
    setTitle("Project Creation");
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    setResizable(false);//w  ww  . j a va  2  s .com
    Container contentPane = getContentPane();
    contentPane.setLayout(null);

    //---- button1 ----
    button1.setText("Create project");
    button1.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            button1ActionPerformed(e);
        }
    });
    contentPane.add(button1);
    button1.setBounds(new Rectangle(new Point(340, 170), button1.getPreferredSize()));
    contentPane.add(textField1);
    textField1.setBounds(10, 25, 245, textField1.getPreferredSize().height);

    //---- label1 ----
    label1.setText("Project Name");
    contentPane.add(label1);
    label1.setBounds(new Rectangle(new Point(10, 5), label1.getPreferredSize()));

    //---- comboBox1 ----
    comboBox1.setModel(new DefaultComboBoxModel<>(new String[] { "Minecraft Forge", "MCP", "Bukkit" }));
    comboBox1.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            comboBox1ItemStateChanged(e);
        }
    });
    contentPane.add(comboBox1);
    comboBox1.setBounds(10, 70, 245, comboBox1.getPreferredSize().height);

    //---- label2 ----
    label2.setText("Modification API");
    contentPane.add(label2);
    label2.setBounds(new Rectangle(new Point(10, 50), label2.getPreferredSize()));

    //---- comboBox2 ----
    comboBox2.setModel(new DefaultComboBoxModel<>(new String[] { "1.8.9", "1.7.10" }));
    contentPane.add(comboBox2);
    comboBox2.setBounds(10, 120, 245, comboBox2.getPreferredSize().height);

    //---- label3 ----
    label3.setText("Minecraft Version");
    contentPane.add(label3);
    label3.setBounds(new Rectangle(new Point(10, 100), label3.getPreferredSize()));

    //---- button2 ----
    button2.setText("Cancel");
    button2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            button2ActionPerformed(e);
        }
    });
    contentPane.add(button2);
    button2.setBounds(new Rectangle(new Point(10, 170), button2.getPreferredSize()));

    { // compute preferred size
        Dimension preferredSize = new Dimension();
        for (int i = 0; i < contentPane.getComponentCount(); i++) {
            Rectangle bounds = contentPane.getComponent(i).getBounds();
            preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
            preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
        }
        Insets insets = contentPane.getInsets();
        preferredSize.width += insets.right;
        preferredSize.height += insets.bottom;
        contentPane.setMinimumSize(preferredSize);
        contentPane.setPreferredSize(preferredSize);
    }
    setSize(480, 240);
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:CircleOfSquares.java

public void layoutContainer(Container parent) {

    int rowCount = rows;
    int colCount = hComponentCellWidths.length;
    Insets parentInsets = parent.insets();
    int componentCount = parent.countComponents();

    if (componentCount == 0) {
        return;// w w w  . j  ava2  s .c om
    }

    // Calculate the width and height of each grid cell. The height will
    // be the height of each component, but the width may not. The width
    // of a component will be some multiple of a grid cell width. The
    // number of grid cells for each component is defined by the
    // hComponentCellWidths array. w is width of each grid cell. h is
    // height of each grid cell.
    Dimension parentDim = parent.size();
    int w = parentDim.width - (parentInsets.left + parentInsets.right);
    int h = parentDim.height - (parentInsets.top + parentInsets.bottom);
    w /= cols;
    h /= rowCount;

    // For each row and column of components (not grid cells) position
    // the component.
    for (int c = 0, x = parentInsets.left; c < colCount; c++) {
        for (int r = 0, y = parentInsets.top; r < rowCount; r++) {

            int i = r * colCount + c;
            if (i < componentCount) {
                parent.getComponent(i).reshape(x, y, w * hComponentCellWidths[c], h);
            }
            y += h;
        }
        x += (w * hComponentCellWidths[c]);
    }
}

From source file:self.philbrown.javaQuery.$.java

/**
 * If the first view of the current selection is a subclass of {@link AdapterView}, this will loop through all the 
 * adapter data and invoke the given function, passing the varargs:
 * <ol>//from   www .ja  va  2  s .  c  om
 * <li>the item from the adapter
 * <li>the index
 * </ol>
 * Otherwise, if the first view in the current selection is a subclass of {@link Container}, {@code each} will
 * loop through all the child views, and wrap each one in a javaQuery object. The invoked
 * function will receive it, and an int for the index of the selected child view.
 * @param function Function the function to invoke
 * @return this
 */
public $ children(Function function) {
    if (view(0) instanceof Container) {
        Container group = (Container) view(0);
        for (int i = 0; i < group.getComponentCount(); i++) {
            function.invoke($.with(group.getComponent(i)), i);
        }
    }
    return this;
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Loops through all the sibling views of the first view in the current selection, and wraps 
 * each in a javaQuery object. When invoked, the given function will receive two parameters:
 * <ol>/*from w  ww.j  a va  2  s .com*/
 * <li>the javaQuery for the view
 * <li>the child index of the sibling
 * </ol>
 * @param function receives the javaQuery for the view, and the index for arg1
 */
public $ siblings(Function function) {
    Component parent = view(0).getParent();
    if (parent != null && parent instanceof Container) {
        Container group = (Container) parent;
        for (int i = 0; i < group.getComponentCount(); i++) {
            function.invoke($.with(group.getComponent(i)), i);
        }
    }
    return this;
}

From source file:net.openbyte.gui.WelcomeFrame.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - Gary Lee
    scrollPane1 = new JScrollPane();
    list1 = new JList();
    button1 = new JButton();
    label2 = new JLabel();
    button2 = new JButton();
    button3 = new JButton();
    button4 = new JButton();
    button5 = new JButton();
    scrollPane2 = new JScrollPane();
    xImagePanel1 = new JXImagePanel();
    button6 = new JButton();
    button7 = new JButton();
    button8 = new JButton();

    //======== this ========
    setTitle("Welcome to OpenByte");
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setResizable(false);//from   w  ww . j av a2 s  .c o m
    Container contentPane = getContentPane();
    contentPane.setLayout(null);

    //======== scrollPane1 ========
    {
        scrollPane1.setBorder(new TitledBorder(LineBorder.createGrayLineBorder(), "Recent Projects"));

        //---- list1 ----
        list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        list1.setBackground(new Color(240, 240, 240));
        list1.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                list1ValueChanged(e);
            }
        });
        scrollPane1.setViewportView(list1);
    }
    contentPane.add(scrollPane1);
    scrollPane1.setBounds(15, 10, 165, 340);

    //---- button1 ----
    button1.setText("Open Project");
    button1.setEnabled(false);
    button1.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            button1ActionPerformed(e);
        }
    });
    contentPane.add(button1);
    button1.setBounds(105, 355, 110, button1.getPreferredSize().height);

    //---- label2 ----
    label2.setText("Media");
    contentPane.add(label2);
    label2.setBounds(new Rectangle(new Point(605, 210), label2.getPreferredSize()));

    //---- button2 ----
    button2.setText("Minecraft Forums");
    button2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            button2ActionPerformed(e);
        }
    });
    contentPane.add(button2);
    button2.setBounds(500, 230, 151, button2.getPreferredSize().height);

    //---- button3 ----
    button3.setText("GitHub");
    button3.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            button3ActionPerformed(e);
        }
    });
    contentPane.add(button3);
    button3.setBounds(500, 260, 150, button3.getPreferredSize().height);

    //---- button4 ----
    button4.setText("+");
    button4.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            button4ActionPerformed(e);
        }
    });
    contentPane.add(button4);
    button4.setBounds(15, 355, 45, button4.getPreferredSize().height);

    //---- button5 ----
    button5.setText("-");
    button5.setEnabled(false);
    button5.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            button5ActionPerformed(e);
        }
    });
    contentPane.add(button5);
    button5.setBounds(60, 355, 40, button5.getPreferredSize().height);

    //======== scrollPane2 ========
    {
        scrollPane2.setBorder(null);
        scrollPane2.setViewportView(xImagePanel1);
    }
    contentPane.add(scrollPane2);
    scrollPane2.setBounds(210, 25, 445, 160);

    //---- button6 ----
    button6.setText("Preferences");
    button6.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            button6ActionPerformed(e);
        }
    });
    contentPane.add(button6);
    button6.setBounds(500, 290, 150, 30);

    //---- button7 ----
    button7.setText("About");
    button7.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            button7ActionPerformed(e);
        }
    });
    contentPane.add(button7);
    button7.setBounds(500, 320, 150, 30);

    //---- button8 ----
    button8.setText("Plugins");
    button8.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            button8ActionPerformed(e);
        }
    });
    contentPane.add(button8);
    button8.setBounds(500, 350, 150, 30);

    { // compute preferred size
        Dimension preferredSize = new Dimension();
        for (int i = 0; i < contentPane.getComponentCount(); i++) {
            Rectangle bounds = contentPane.getComponent(i).getBounds();
            preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
            preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
        }
        Insets insets = contentPane.getInsets();
        preferredSize.width += insets.right;
        preferredSize.height += insets.bottom;
        contentPane.setMinimumSize(preferredSize);
        contentPane.setPreferredSize(preferredSize);
    }
    setSize(675, 425);
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}

From source file:main.java.gui.java

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - BOHDAN Korinnyi
    test = new JFrame();
    label1 = new JLabel();
    textField1 = new JTextField();
    label2 = new JLabel();
    textField2 = new JTextField();
    label3 = new JLabel();
    label4 = new JLabel();
    textField3 = new JTextField();
    textField4 = new JTextField();
    button1 = new JButton();
    button2 = new JButton();
    label5 = new JLabel();
    label6 = new JLabel();

    //======== test ========
    {// w ww .  j ava 2  s.  co  m
        test.setTitle("Pay mobile account");
        Container testContentPane = test.getContentPane();
        testContentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u0421\u0443\u043c\u0430");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 4f));
        testContentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(35, 30), label1.getPreferredSize()));

        //---- textField1 ----
        textField1.setColumns(10);
        testContentPane.add(textField1);
        textField1.setBounds(150, 30, 105, textField1.getPreferredSize().height);

        //---- label2 ----
        label2.setText("\u041d\u043e\u043c\u0435\u0440");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 4f));
        testContentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(35, 60), label2.getPreferredSize()));

        //---- textField2 ----
        textField2.setText("0674060606");
        textField2.setFont(textField2.getFont().deriveFont(textField2.getFont().getSize() + 2f));
        testContentPane.add(textField2);
        textField2.setBounds(150, 60, 105, textField2.getPreferredSize().height);

        //---- label3 ----
        label3.setText("\u041b\u043e\u0433\u0456\u043d");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 4f));
        testContentPane.add(label3);
        label3.setBounds(new Rectangle(new Point(35, 95), label3.getPreferredSize()));

        //---- label4 ----
        label4.setText("\u041f\u0430\u0440\u043e\u043b\u044c");
        label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 4f));
        testContentPane.add(label4);
        label4.setBounds(new Rectangle(new Point(35, 125), label4.getPreferredSize()));
        testContentPane.add(textField3);
        textField3.setBounds(150, 95, 105, textField3.getPreferredSize().height);
        testContentPane.add(textField4);
        textField4.setBounds(150, 125, 105, 20);

        //---- button1 ----
        button1.setText("\u041e\u043f\u043b\u0430\u0442\u0438\u0442\u0438");
        button1.setFont(button1.getFont().deriveFont(button1.getFont().getStyle() | Font.BOLD,
                button1.getFont().getSize() + 2f));
        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String strTemp = textField1.getText();
                int cash = Integer.parseInt(strTemp);
                if (cash < 1) {
                    JOptionPane.showMessageDialog(null, "    '", "",
                            JOptionPane.OK_OPTION);
                    textField1.setText("0");
                } else if (textField3.getText().equals("test4") && textField4.getText().equals("12345")) {
                    check c = new check();
                    pay p = new pay();
                    getstatus g = new getstatus();
                    try {
                        c.connection(c.PaymentCollectionRequest("38" + getNumber(), getMoney()));
                        g.connection(c.PaymentStatusRequest());
                        p.connection(c.PaymentCollectionRequest("38" + getNumber(), getMoney()));
                        g.connection(c.PaymentStatusRequest());
                        information i = new information();
                        daoImplements h = new daoImplements();
                        long curTime = System.currentTimeMillis();
                        String curStringDate = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(curTime);

                        i.setIdTransaction(getTransaction.setGetTransaction());
                        i.setData(curStringDate);
                        i.setNumber(Integer.parseInt(getNumber()));
                        i.setSuma(Integer.parseInt(getMoney()));
                        i.setStatus(parserStatus.getStatusParsing());
                        h.addInfo(i);

                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (ParseException e2) {
                        // TODO Auto-generated catch block
                        e2.printStackTrace();
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "    ", "",
                            JOptionPane.OK_OPTION);
                    System.exit(0);
                }
            }

        });
        testContentPane.add(button1);
        button1.setBounds(150, 155, 115, 25);

        //---- button2 ----
        button2.setText("\u0406\u0441\u0442\u043e\u0440\u0456\u044f");
        button2.setFont(button2.getFont().deriveFont(button2.getFont().getStyle() | Font.BOLD,
                button2.getFont().getSize() + 2f));
        button2.setActionCommand("\u0406\u0441\u0442\u043e\u0440\u0456\u044f");
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tableData t = new tableData();
            }
        });
        testContentPane.add(button2);
        button2.setBounds(15, 155, 115, 25);

        //---- label5 ----
        label5.setText(
                "\u0422\u0435\u0441\u0442\u043e\u0432\u0438\u0439 \u0441\u0435\u0440\u0432\u0456\u0441 \u043f\u043e\u043f\u043e\u0432\u043d\u0435\u043d\u043d\u044f \u043c\u043e\u0431\u0456\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0445\u0443\u043d\u043a\u0443");
        label5.setFont(label5.getFont().deriveFont(label5.getFont().getStyle() & ~Font.ITALIC));
        testContentPane.add(label5);
        label5.setBounds(15, 0, 255, 20);

        //---- label6 ----
        label6.setText("38");
        label6.setFont(label6.getFont().deriveFont(label6.getFont().getSize() + 4f));
        testContentPane.add(label6);
        label6.setBounds(new Rectangle(new Point(130, 60), label6.getPreferredSize()));

        { // compute preferred size
            Dimension preferredSize = new Dimension();
            for (int i = 0; i < testContentPane.getComponentCount(); i++) {
                Rectangle bounds = testContentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = testContentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            testContentPane.setMinimumSize(preferredSize);
            testContentPane.setPreferredSize(preferredSize);
        }
        test.pack();
        test.setLocationRelativeTo(test.getOwner());
    }
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}