JPanel (@NotNull List<? extends JButton> buttons) { JPanel buttonsPanel = new NonOpaquePanel(); buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); for (int i = 0; i < buttons.size(); i++) { JComponent button = buttons.get(i); Insets insets = button.getInsets(); buttonsPanel.add(button); if (i < buttons.size() - 1) { int gap = BASE_BUTTON_GAP.get() - insets.left - insets.right; buttonsPanel.add(Box.createRigidArea(new Dimension(gap, 0))); } } return buttonsPanel; }