I'm still new to Java and I'm enjoying messing around with it, so please just humor me on this. I know about the layout manager but I'm interested in the mechanics of swing so I'm using absolute positioning. Any insights would be greatly appreciated.
So I've noticed an annoying behavior when I add a JLabel to a JPanel. For Example if I set it up like this:
JFrame frame=new JFrame("Test Frame");
frame.setSize(800,500);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable (false);
JPanel conPane=new JPanel();
conPane.setLayout(null);
frame.setContentPane(conPane);
conPane.setBounds(0,0,1600,1000);
conTP.setFocusable(true);
frame.setVisible(true);
So now I move the conPane panel...
conPane.setBounds(-200,-200,1600,1000);
And then make a new JLabel....
ImageIcon ico=new ImageIcon("directory/testimage.gif");
JLabel myLabel=new JLabel(ico);myLabel.setLayout(null);
myLabel.setBounds(300,300,200,200);
And add it to conPane...
conPane.add(myLabel);
And it resets conPane back to it's starting position. Essentially doing setBounds(0,0,1600,1000) without my permission;
It also happens if I move a label, change it's icon or pretty much do anything involving altering a child of conPane.
How can I stop it?