I am trying to use GridBagLayout. I need one JLabel centered vertically and horizontally - that is easy, I do not even have to create any GridBagConstraints. I also want to put a JButton in right-bottom corner and when I try to do it, my centered panel is moving to left or the button is moving up.
EXPECTING GETTING THIS OR THIS
+-----------+ +-----------+ +-----------+
| | | | | |
| | | | | |
| | | | | |
| +---+ | | +---+ | | +---+ |
| | | | | | | | | | | |
| +---+ | | +---+ | | +---++---+|
| | | | | | ||
| | | | | +---+|
| +---+ | +---+ | |
| | | | | | | |
+-------+---+ +-------+---+ +-----------+
bigPanel = new JPanel();
bigPanel.setPreferredSize(new Dimension(320, 640));
bigPanel.setLayout(new GridBagLayout());
label = new JLabel();
label.setPreferredSize(new Dimension(100,95));
button = new JButton();
button.setPreferredSize(new Dimension(100,25));
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.CENTER;
bigPanel.add(label, c);
c.anchor = GridBagConstraints.LAST_LINE_END;
bigPanel.add(button, c);
I was also trying to use other constraints which are described here http://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html but every time something goes wrong.