Hi I am working on swing application but I am facing one problem.
When I first run application JPanel
is positioned at proper position
where I decided to set with components inside. But problem occur when
I minimize & again maximize frame window jpanel
automatically changes
it's position.
Below images shows that difference
As we can see on second image components changes it's position automatically.
For this I written below code,
jpanel_addPurchase = new JPanel();
jpanel_addPurchase.setLayout(null);
jpanel_addPurchase.setBounds(400, 0, 500, 500);
jpanel_addPurchase.setBackground(Color.white);
JLabel lbl_title = new JLabel("Purchase Form");
lbl_title.setBounds(90, 20, 100, 100);
jpanel_addPurchase.add(lbl_title);
And added this panel in frame using,
setContentPane(getJPanel());
Where I am going wrong?
I think the original (non-broken) layout looks quirky and would make it difficult for the end user to follow the rows and labels/fields. I suggest instead using a
GroupLayout
to right align the labels, and left align the fields that contain the values. Like this: