Elements appearing in the up position
I noticed this kinda of event some weeks ago, but I ignored, now it's making me curious. the last element that I add always end up in the up position of the screen, no matter how much I try to alter the positions of the elements created, the result is the same.
It was supposed to have two buttons inline.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
import javax.swing.border.TitledBorder;
public class Todolist extends JFrame{
private JLabel jcriar, jtexto, jnum, jtexto1;
private JButton btcriar, btrem;
private JTextField txtcriar;
private JPanel jp;
int t = 0;
public static void main(String[] args) {
JFrame op = new Todolist();
op.setVisible(true);
op.setLayout(null);
op.setSize(500, 400);
op.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public Todolist(){
elemen();
}
public void elemen(){
jcriar = new JLabel("criar/remover");
txtcriar = new JTextField();
btcriar = new JButton("criar");
btrem = new JButton("remover");
jp = new JPanel();
jp.setBounds(230, 100, 150, 200);
jp.setLayout(null);
jp.setBorder(new TitledBorder(""));
jcriar.setBounds(30, 30, 100, 20);
txtcriar.setBounds(131, 30, 100, 20);
btcriar.setBounds(232, 30, 80, 20);
btrem.setBounds(314, 30, 80, 20);
add(jcriar);
add(txtcriar);
add(btcriar);
add(jp);
add(btrem);
}
}
}