0

enter image description here

I want to align panel2 components with panel1. How is it possible? Please help!

Community
  • 1
  • 1
  • (1+) Not sure why you got a down vote. It's a good question and I wish I knew the answer. The problem is that layout managers work only for a given panel and so they know nothing about components added to another panel so they don't know the size of the other components. – camickr Aug 18 '17 at 14:41
  • The only think I can suggest is that you might be able use "relative" column sizes and make them the same for both panels. That is the first column is 33% and the second column 67%. So you could use a GridBagLayout and play with the weightX parameters. Check out this posting: https://stackoverflow.com/questions/43240363/set-components-in-alternating-columns-gridbaglayout/43252262#43252262. It shows how you can assign widths/weights for the GridBagLayout. The question also has a link to the Swing tutorial on `How to Use GridBagLayout` for more information on using the constraints. – camickr Aug 18 '17 at 14:52
  • I have used weightX parameter. I have divided it in 0.4D and 0.6D but then also this is happening. I guess this depends on the label string length. If by any method I can fix the starting point of second component then I can achieve this. But anchor is also not working. – Surabhi Choudhary Aug 18 '17 at 15:08
  • If you're willing to forgo a layout manager, you can always set the location of the components directly. – mm8511 Aug 18 '17 at 15:22
  • No I am not willing to forgo, I want to know whether I can do this by gridbagconstrainsts. – Surabhi Choudhary Aug 18 '17 at 16:41
  • Although intended for GUI builders, you might look at [`GroupLayout`](https://docs.oracle.com/javase/tutorial/uiswing/layout/group.html), for [example](https://stackoverflow.com/a/8504753/230513). – trashgod Aug 18 '17 at 23:43
  • @jennifer what have you tried so far? – 1ac0 Aug 19 '17 at 10:31

0 Answers0