List of usage examples for java.awt Container getComponentCount
public int getComponentCount()
From source file:org.kineticsystem.commons.layout.TetrisLayout.java
/** * Lay out components in the specified container. * @param parent The container which needs to be laid out. *//*from www.j a v a 2s .com*/ public void layoutContainer(Container parent) { /* * This method synchronizes on the tree lock of the component. This tree * lock is an object that can be used to provide thread-safe access to * the layout manager in case different threads are simultaneously * adding or removing components. The tree lock object is used as a * synchronization point for all of the methods associated with laying * out containers and invalidating components, and it is good * programming practice to use it to ensure a thread-safe * implementation. */ synchronized (parent.getTreeLock()) { // Layout components. if (containerSize == null) { setup(parent); } Insets insets = parent.getInsets(); int componentNumber = parent.getComponentCount(); if (componentNumber == 0) { return; } Dimension size = parent.getSize(); cGaps[0].setIncSize(cGaps[0].getSize()); for (int i = 1; i < cBars.length + 1; i++) { cGaps[i].setIncSize(cGaps[i].getSize() + cGaps[i - 1].getIncSize()); } rGaps[0].setIncSize(rGaps[0].getSize()); for (int i = 1; i < rBars.length + 1; i++) { rGaps[i].setIncSize(rGaps[i].getSize() + rGaps[i - 1].getIncSize()); } int actualGapFreeWidth = Math .max(size.width - insets.left - insets.right - cGaps[cBars.length].getIncSize(), 0); int actualGapFreeHeight = Math .max(size.height - insets.top - insets.bottom - rGaps[rBars.length].getIncSize(), 0); for (Map.Entry<Component, Cell> entry : constraintsMap.entrySet()) { Component comp = (Component) entry.getKey(); Cell cell = (Cell) entry.getValue(); if (cell != null) { // Actual cell position. int x0 = (int) Math.round(cSizes[cell.getCol()].evaluate(actualGapFreeWidth)); int y0 = (int) Math.round(rSizes[cell.getRow()].evaluate(actualGapFreeHeight)); int x1 = (int) Math.round(cSizes[cell.getCol() + cell.getCols()].evaluate(actualGapFreeWidth)); int y1 = (int) Math.round(rSizes[cell.getRow() + cell.getRows()].evaluate(actualGapFreeHeight)); // Actual cell dimension. int w = x1 - x0; int h = y1 - y0; // Component position correction. int xCorrection = insets.left + cGaps[cell.getCol()].getIncSize(); int yCorrection = insets.top + rGaps[cell.getRow()].getIncSize(); // Component dimension correction. int wCorrection = cGaps[cell.getCol() + cell.getCols() - 1].getIncSize() - cGaps[cell.getCol()].getIncSize(); int hCorrection = rGaps[cell.getRow() + cell.getRows() - 1].getIncSize() - rGaps[cell.getRow()].getIncSize(); // Preferred component dimension. int wComp = comp.getPreferredSize().width; int hComp = comp.getPreferredSize().height; int fill = cell.getFill(); int anchor = cell.getAnchor(); switch (fill) { case Cell.NONE: { if (wComp > w) { wComp = w; } if (hComp > h) { hComp = h; } switch (anchor) { case Cell.FIRST_LINE_START: x0 += xCorrection; y0 += yCorrection; break; case Cell.PAGE_START: x0 += xCorrection + (w - wComp) / 2; y0 += yCorrection; break; case Cell.FIRST_LINE_END: x0 += xCorrection + w + wCorrection - wComp; y0 += yCorrection; break; case Cell.LINE_START: x0 += xCorrection; y0 += yCorrection + (h - hComp) / 2; break; case Cell.CENTER: x0 += xCorrection + (w - wComp) / 2; y0 += yCorrection + (h - hComp) / 2; break; case Cell.LINE_END: x0 += xCorrection + w + wCorrection - wComp; y0 += yCorrection + (h - hComp) / 2; break; case Cell.LAST_LINE_START: x0 += xCorrection; y0 += yCorrection + h + hCorrection - hComp; break; case Cell.PAGE_END: x0 += xCorrection + (w - wComp) / 2; y0 += yCorrection + h + hCorrection - hComp; break; case Cell.LAST_LINE_END: x0 += xCorrection + w + wCorrection - wComp; y0 += yCorrection + h - hCorrection - hComp; break; } w = Math.min(w, wComp) + wCorrection; h = Math.min(h, hComp) + hCorrection; break; } case Cell.PROPORTIONAL: { double ratio = Math.min((double) ((double) w / (double) wComp), (double) ((double) h / (double) hComp)); wComp = (int) Math.round(wComp * ratio); hComp = (int) Math.round(hComp * ratio); switch (anchor) { case Cell.FIRST_LINE_START: x0 += xCorrection; y0 += yCorrection; break; case Cell.PAGE_START: x0 += xCorrection + (w - wComp) / 2; y0 += yCorrection; break; case Cell.FIRST_LINE_END: x0 += xCorrection + wCorrection + w - wComp; y0 += yCorrection; break; case Cell.LINE_START: x0 += xCorrection; y0 += yCorrection + (h - hComp) / 2; break; case Cell.CENTER: x0 += xCorrection + (w - wComp) / 2; y0 += yCorrection + (h - hComp) / 2; break; case Cell.LINE_END: x0 += xCorrection + wCorrection + w - wComp; y0 += yCorrection + (h - hComp) / 2; break; case Cell.LAST_LINE_START: x0 += xCorrection; y0 += yCorrection + hCorrection + h - hComp; break; case Cell.PAGE_END: x0 += xCorrection + (w - wComp) / 2; y0 += yCorrection + hCorrection + h - hComp; break; case Cell.LAST_LINE_END: x0 += xCorrection + wCorrection + w - wComp; y0 += yCorrection + hCorrection + h - hComp; break; } w = Math.min(w, wComp) + wCorrection; h = Math.min(h, hComp) + hCorrection; break; } case Cell.BOTH: { x0 += xCorrection; y0 += yCorrection; w += wCorrection; h += hCorrection; break; } case Cell.HORIZONTAL: { if (hComp > h) { hComp = h; } switch (anchor) { case Cell.FIRST_LINE_START: case Cell.PAGE_START: case Cell.FIRST_LINE_END: y0 += yCorrection; break; case Cell.LINE_START: case Cell.CENTER: case Cell.LINE_END: y0 += yCorrection + (h - hComp) / 2; break; case Cell.LAST_LINE_START: case Cell.PAGE_END: case Cell.LAST_LINE_END: y0 += yCorrection + h + hCorrection - hComp; break; } x0 += xCorrection; w += wCorrection; h = Math.min(h, hComp) + hCorrection; break; } case Cell.VERTICAL: { if (wComp > w) { wComp = w; } switch (anchor) { case Cell.FIRST_LINE_START: case Cell.LINE_START: case Cell.LAST_LINE_START: x0 += xCorrection; break; case Cell.PAGE_START: case Cell.CENTER: case Cell.PAGE_END: x0 += xCorrection + (w - wComp) / 2; break; case Cell.FIRST_LINE_END: case Cell.LINE_END: case Cell.LAST_LINE_END: x0 += xCorrection + w + wCorrection - wComp; break; } y0 += yCorrection; w = Math.min(w, wComp) + wCorrection; h += hCorrection; break; } } comp.setBounds(x0, y0, w, 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 v a 2 s .c o m*/ 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: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>//ww w. j a v a 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>/* w ww . j a va 2 s . c om*/ * <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 ww w . j a v a2 s . com*/ 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 w w . ja va 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 }