I'm trying to make a game with a menu and therefor I'm using the setAlignment which seem to have no effect.
(I'm not sure how I attach images so it might not run.
package fold; import javax.swing.*; //Pakke der hjælper med at lave vinduet import javax.swing.JFrame; import java.awt.*; import java.awt.event.*; import javax.swing.JLabel; import javax.swing.ImageIcon; public class GameFrame extends JFrame { // CENTER regions størrelse static final int SCREEN_WIDTH = 2296; static final int SCREEN_HEIGHT = 1280; // De forskellige JPanels JLabel topMenu; JLabel mineCounter1, mineCounter2, mineCounter3; JLabel timer1, timer2, timer3; public static GameFrame frame; JButton newGameButton; GameFrame() { setLayout(new BorderLayout()); // adding top menu //add(new GamePanel(), BorderLayout.CENTER); addTopMenu(); setSize(SCREEN_WIDTH, SCREEN_HEIGHT); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); } public static void main(String[] args) { frame = new GameFrame(); } // Indeling af kode. Den del af koden som laver top menuen. void addTopMenu() { topMenu = new JLabel(); topMenu.setIcon(new ImageIcon("Images/menuBackground.png")); topMenu.setLayout(new BoxLayout(topMenu, BoxLayout.Y_AXIS)); JButton optionButton = new JButton(); optionButton.setAlignmentX(LEFT_ALIGNMENT); String iconfilePath = this.getClass().getClassLoader().getResource("Images/gear.png").getFile(); optionButton.setIcon(new ImageIcon(iconfilePath)); optionButton.setBorder(BorderFactory.createEmptyBorder()); optionButton.setContentAreaFilled(false); optionButton.setFocusable(false); topMenu.add(optionButton); JPanel iconMenu = new JPanel(); iconMenu.setLayout(new BoxLayout(iconMenu, BoxLayout.X_AXIS)); // topMenu.setLayout(new GridLayout(1, 3, 0, 300)); // topMenu.add(Box.createRigidArea(new Dimension(0, 0))); // topMenu.add(Box.createRigidArea(new Dimension(0, 0))); mineCounter3 = new JLabel(); mineCounter3.setIcon(new ImageIcon("Images/Numbers/1.png")); mineCounter3.setAlignmentX(LEFT_ALIGNMENT); iconMenu.add(mineCounter3); mineCounter2 = new JLabel(); mineCounter2.setIcon(new ImageIcon("Images/Numbers/9.png")); mineCounter2.setAlignmentX(LEFT_ALIGNMENT); iconMenu.add(mineCounter2); mineCounter1 = new JLabel(); mineCounter1.setIcon(new ImageIcon("Images/Numbers/9.png")); mineCounter1.setAlignmentX(LEFT_ALIGNMENT); iconMenu.add(mineCounter1); // topMenu.add(Box.createRigidArea(new Dimension(0, 0))); // topMenu.add(Box.createRigidArea(new Dimension(830, 0))); newGameButton = new JButton(); newGameButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("new game"); } }); newGameButton.setIcon(new ImageIcon("Images/Defualt.png")); newGameButton.setBorder(BorderFactory.createEmptyBorder()); newGameButton.setContentAreaFilled(false); newGameButton.setFocusable(false); newGameButton.setAlignmentX(CENTER_ALIGNMENT); iconMenu.add(newGameButton); // .add(Box.createRigidArea(new Dimension(830, 0))); timer3 = new JLabel(); timer3.setIcon(new ImageIcon("Images/Numbers/0.png")); timer3.setAlignmentX(RIGHT_ALIGNMENT); iconMenu.add(timer3); timer2 = new JLabel(); timer2.setIcon(new ImageIcon("Images/Numbers/0.png")); timer2.setAlignmentX(RIGHT_ALIGNMENT); iconMenu.add(timer2); timer1 = new JLabel(); timer1.setIcon(new ImageIcon("Images/Numbers/0.png")); timer1.setAlignmentX(RIGHT_ALIGNMENT); iconMenu.add(timer1); iconMenu.setAlignmentY(LEFT_ALIGNMENT); topMenu.add(iconMenu); add(topMenu, BorderLayout.NORTH); } public void changeIcon(String imagePath) { String iconfilePath = this.getClass().getClassLoader().getResource(imagePath).getFile(); newGameButton.setIcon(new ImageIcon(iconfilePath)); } }