0
I want to align a single button to the Jpanel, but I’m not succeeding, 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);
}
}
Line up like, left?
– user28595
That’s right, I forgot to say.
– leo4
Did the answer help you? If yes, you can mark it as accepted by clicking on
v
the left of the answer :)– user28595