I haven't used Swing for a long time, I have already forgotten what and how. I create a JPanel object, ask it the layout manager GridBagLayout. I have the elements. Then I put this panel on my JFrame. It is necessary that the table be stretched, but there is no button. But in my campaign, the entire panel containing the components does not stretch, so, as if inside, too, nothing changes. Poke please where I am stupid.
package forms; import info.Informer; import javax.swing.*; import java.awt.*; /** * User: Jakeroid * Date: 24-11-2012 * Time: 17:38 */ public class MainForm extends JFrame { public MainForm() { super(Informer.getInfoString()); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setSize(500, 250); JPanel content = new JPanel(new GridBagLayout()); ImageIcon addIcon = new ImageIcon(getClass().getResource("/resource/add.png")); ImageIcon editIcon = new ImageIcon(getClass().getResource("/resource/edit.png")); ImageIcon deleteIcon = new ImageIcon(getClass().getResource("/resource/delete.png")); ImageIcon updateIcon = new ImageIcon(getClass().getResource("/resource/update.png")); JButton addButton = new JButton(addIcon); JButton editButton = new JButton(editIcon); JButton deleteButton = new JButton(deleteIcon); JButton updateButton = new JButton(updateIcon); //ΠΠ°ΡΡΠΈΠ² ΡΠΎΠ΄Π΅ΡΠΆΠ°ΡΠΈΠΉ Π·Π°Π³ΠΎΠ»ΠΎΠΊΠΈ ΡΠ°Π±Π»ΠΈΡΡ Object[] headers = { "Name", "Surname", "Telephone" }; //ΠΠ°ΡΡΠΈΠ² ΡΠΎΠ΄Π΅ΡΠΆΠ°ΡΠΈΠΉ ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΡ Π΄Π»Ρ ΡΠ°Π±Π»ΠΈΡΡ Object[][] data = { { "John", "Smith", "1112221" }, { "Ivan", "Black", "2221111" }, { "George", "White", "3334444" }, { "Bolvan", "Black", "2235111" }, { "Serg", "Black", "2221511" }, { "Pussy", "Black", "2221111" }, { "Tonya", "Red", "2121111" }, { "Elise", "Green", "2321111" }, }; JTable accountsTable = new JTable(data, headers); //setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.NORTHWEST; content.add(updateButton, c); c.gridx = 0; c.gridy = 1; content.add(addButton, c); c.gridx = 0; c.gridy = 2; content.add(editButton, c); c.gridx = 0; c.gridy = 3; content.add(deleteButton, c); c.gridx = 1; c.gridy = 0; c.gridheight = 4; c.fill = GridBagConstraints.BOTH; JScrollPane scrollPane = new JScrollPane(accountsTable); content.add(scrollPane, c); getContentPane().add(content, BorderLayout.CENTER); } }