JComponent () { JPanel panel = new JPanel(new GridBagLayout()); panel.add( new JLabel(myName), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 3, 5), 0, 0) ); panel.add( myTfUrl, new GridBagConstraints(0, 1, 2, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5), 0, 0) ); myTfUrl.setPreferredSize(new Dimension(350, myTfUrl.getPreferredSize().height)); if (myShowPath) { panel.add( new JLabel(myLocation), new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 3, 5), 0, 0) ); panel.add( myTfPath, new GridBagConstraints(0, 3, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 10, 0), 0, 0) ); panel.add( myBtnBrowseLocalPath, new GridBagConstraints(1, 3, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 10, 5), 0, 0) ); ComponentWithBrowseButton.MyDoClickAction.addTo(myBtnBrowseLocalPath, myTfPath); myBtnBrowseLocalPath.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ignored) { FileChooserDescriptor descriptor = getChooserDescriptor(); FileChooser.chooseFile(descriptor, myProject, null, file -> myTfPath.setText(file.getPath().replace('/', File.separatorChar))); } }); } return panel; }