In the JPanel I placed JTextField and JButton, as the layout I'm using GridBagLayout which is left to default align (center). However because of the size of whole JFrame I would like to get JTextField to left and JButton to right. How do I do that :?:
private GridBagLayout gbag = new GridBagLayout();
private GridBagConstraints gbc = new GridBagConstraints();
private Border bs = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
.
.
.
.
public void setupIndexPanel()
{
panelIndex = new JPanel();
panelIndex.setBorder(new TitledBorder(bs, "Index File Path"));
panelIndex.setLayout(gbag);
tfIndex = new JTextField(20);
tfIndex.setEditable(false);
gbc.gridx = 0;
gbc.gridy = 0;
gbag.setConstraints(tfIndex, gbc);
panelIndex.add(tfIndex);
btnIndex = new JButton("Get index");
btnIndex.setPreferredSize(new Dimension(100, 30));
btnIndex.addActionListener(this);
gbc.gridx = 1;
gbc.gridy = 0;
gbag.setConstraints(btnIndex, gbc);
panelIndex.add(btnIndex);
}