Hi! I am going thro the flow layout tutorials and am attempting to set-up a panel with 3 labels that are left center and right in the panel. My code is so super close, I am sure it is something small I am missing, but my code has the images appear to be left, left-center, right
What should I change in my code to make the images appear left - center - right?
import javax.swing.*; import java.awt.event.*; import javax.swing.border.LineBorder; import java.awt.*; public class Data { JFrame frame = new JFrame(); JPanel mainPanel = new JPanel(); JPanel secondPanel = new JPanel(); String playerimage; String cpuimage; String BattlesWon = "0"; String BattlesLost = "0"; String Gold = "0"; String PlayerLevel = "1"; public static void main(String args[]) { new Data().start(); } public void start() { JLabel myLabel = new JLabel("Enter Player Name:"); JPanel pnlHeaderInfo = new JPanel(); JPanel pnlCharacters = new JPanel(); JPanel pnlNextButton = new JPanel(); JTextField myText = new JTextField(20); myLabel.setAlignmentX(JTextField.CENTER_ALIGNMENT); pnlHeaderInfo.setPreferredSize(new Dimension(300, 60)); pnlHeaderInfo.setLayout(new FlowLayout()); pnlHeaderInfo.add(myLabel); pnlHeaderInfo.add(myText); pnlHeaderInfo.setBorder(new LineBorder(Color.RED, 3)); mainPanel.setPreferredSize(new Dimension(600, 400)); mainPanel.add(pnlHeaderInfo); JLabel lblLeftChar1 = new JLabel(); JLabel lblCenterChar2 = new JLabel(); JLabel lblRightChar3 = new JLabel(); lblLeftChar1.setMinimumSize(new Dimension(141,244)); lblLeftChar1.setMaximumSize(new Dimension(141,244)); lblLeftChar1.setIcon(new ImageIcon(getClass().getResource("/resources/__Link.jpg"))); lblCenterChar2.setMinimumSize(new Dimension(141,244)); lblCenterChar2.setMaximumSize(new Dimension(141,244)); lblCenterChar2.setIcon(new ImageIcon(getClass().getResource("/resources/__Mario.png"))); lblRightChar3.setMinimumSize(new Dimension(141,244)); lblRightChar3.setMaximumSize(new Dimension(141,244)); lblRightChar3.setIcon(new ImageIcon(getClass().getResource("/resources/__Pikachu.png"))); pnlCharacters.setPreferredSize(new Dimension(496, 256)); pnlCharacters.setLayout(new BorderLayout()); pnlCharacters.add(lblLeftChar1, BorderLayout.LINE_START); pnlCharacters.add(lblCenterChar2, BorderLayout.CENTER); pnlCharacters.add(lblRightChar3, BorderLayout.LINE_END); pnlCharacters.setBorder((new LineBorder(Color.BLUE, 3))); mainPanel.add(pnlCharacters); JButton btnNext = new JButton("Start Game"); btnNext.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //hide the current main panel mainPanel.setVisible(false); beginstagetwo(); } }); btnNext.setMinimumSize(new Dimension(112,29)); btnNext.setMaximumSize(new Dimension(112,29)); pnlNextButton.add(btnNext, BorderLayout.CENTER); pnlNextButton.setBorder((new LineBorder(Color.GREEN))); mainPanel.add(pnlNextButton); frame.add(mainPanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public void beginstagetwo() { JPanel pnlPlayerStats = new JPanel(); pnlPlayerStats.setPreferredSize(new Dimension(300, 60)); JLabel lblPlayerName = new JLabel("Player Name:"); JTextField txtPlayerName = new JTextField(15); lblPlayerName.setAlignmentX(JTextField.CENTER_ALIGNMENT); JLabel lblPlayerGold = new JLabel("Gold:"); JTextField txtPlayerGold = new JTextField(6); lblPlayerGold.setAlignmentX(JTextField.CENTER_ALIGNMENT); pnlPlayerStats.setLayout(new FlowLayout()); pnlPlayerStats.add(lblPlayerName); pnlPlayerStats.add(txtPlayerName); pnlPlayerStats.add(lblPlayerGold); pnlPlayerStats.add(txtPlayerGold); pnlPlayerStats.setBorder(new LineBorder(Color.ORANGE, 3)); secondPanel.setPreferredSize(new Dimension(600, 400)); secondPanel.add(pnlPlayerStats); frame.add(secondPanel); frame.pack(); frame.setVisible(true); } }