I want to align a single button to JPanel, but I'm not getting it, it's using the default layout.
public class Test extends JFrame {
private JButton btn;
private JPanel painel;
private JScrollPane scroll;
private JTextArea tArea;
public Test() {
btn = new JButton("Sair");
btn.setPreferredSize(new Dimension(72, 35));
btn.addActionListener(e -> System.exit(0));
painel = new JPanel();
painel.add(btn, FlowLayout.LEFT); //nao funciona
JScrollPane scroll = new JScrollPane(tArea = new JTextArea());
scroll.setPreferredSize(new Dimension(400, 300));
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
Container cp = getContentPane();
cp.add(painel, "North");
cp.add(scroll, "Center");
getRootPane().setDefaultButton(btn);
setSize(400, 280);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Test().setVisible(true);
}
}