I am designing this GUI the overall frame is using a BorderLayout, then there are 3 panels, the boggle Board panel is using GridLayout, the Enter Words Found Panel (consisting of the JTextArea, Time left JLabel, and Shake Dice JButton) is using BoxLayout with Y-Axis, the Current Word Panel (consisting of the Current Word JLabel, Submit Word JButton, and Score JLabel) is using FlowLayout.
As you can see the JTextArea is not inline along the Y Axis with the Time Left JLabel and Shake Dice JButton, I have no idea why this is happening. If someone could shed some light as to why they're not in line that would be great thank you.
here is my code for the Enter Words Found JPanel:
// Adding words found JPanel
wordFoundPanel = new JPanel();
wordFoundPanel.setLayout(new BoxLayout(wordFoundPanel, BoxLayout.Y_AXIS));
wordFoundPanel.setBorder(new TitledBorder("Enter Words Found"));
wordArea = new JTextArea();
wordArea.setLineWrap(true);
wordArea.setWrapStyleWord(rootPaneCheckingEnabled);
// Adding JScrollPane to the wordArea
scroll = new JScrollPane(wordArea);
scroll.setMinimumSize(new Dimension(200, 180));
scroll.setPreferredSize(new Dimension(200, 180));
scroll.setMaximumSize(new Dimension(200, 180));
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
wordFoundPanel.add(scroll);
// Adding Clock Label
clockLabel = new JLabel("3:00", CENTER);
clockLabel.setMinimumSize(new Dimension(200, 100));
clockLabel.setPreferredSize(new Dimension(200, 100));
clockLabel.setMaximumSize(new Dimension(200, 100));
clockLabel.setFont(new Font("Tahoma", Font.BOLD, 30));
clockLabel.setBorder(new TitledBorder("Time Left"));
wordFoundPanel.add(clockLabel);
// Adding Shake Dice button
shakeDiceButton = new JButton("Shake Dice");
shakeDiceButton.setMinimumSize(new Dimension(200, 100));
shakeDiceButton.setPreferredSize(new Dimension(200, 100));
shakeDiceButton.setMaximumSize(new Dimension(200, 100));
wordFoundPanel.add(shakeDiceButton);
frame.add(wordFoundPanel, BorderLayout.EAST);
In the Fixing Alignment Problems section from How to Use BoxLayout, we can read :
In general, all the components controlled by a top-to-bottom BoxLayout object should have the same X alignment
So just call e.g setAlignmentX(Component.RIGHT_ALIGNMENT);
on your three components, and it will fix this strange display.