I've already set up the menu (the centre boxes) perfectly, but I don't know how I can position the label. Currently what is happening is the label is going below the menu options, and the menu options are pushed to the right.
Here is what I want to happen:
And here is what is happening:
Currently I have my boxes centred with:
this.setAlignmentX(Component.CENTER_ALIGNMENT);
And I have attempted to do the same with my label using:
this.setAlignmentX(Component.BOTTOM_ALIGNMENT);
this.setAlignmentY(Component.LEFT_ALIGNMENT);
Which does nothing.
Sorry the diagram is so bad, I drew it up in MS Paint in about 20 seconds.
Here is the important part of the label
public Label(String text)
{
this.setHorizontalTextPosition(JLabel.CENTER);
this.setVerticalTextPosition(JLabel.CENTER);
this.setHorizontalAlignment(0);
}
And here is where I create the boxlayout:
pnlMain.setLayout(new BoxLayout(pnlMain, BoxLayout.Y_AXIS));
Edit: Here is the main function inside my JFrame extension class. Above the function is just the creation of panels, buttons and labels.
public Window()
{
//Create the JFrame
super("Tank Trouble");
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
//Changes the frame size to your screen size
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) (dimension.getWidth());
int y = (int) (dimension.getHeight());
setSize(x,y);
setResizable(false);
//GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this); //Makes the application go fullscreen
getContentPane().add(pnlMaster);
pnlMaster.add(pnlMenu, "Main Menu");
pnlMaster.add(pnlOptions, "Options");
pnlMaster.add(pnlGame, "Game");
pnlMaster.add(pnlMenu2);
switchTo("Main Menu");
pnlOptions.setLayout(new BoxLayout(pnlOptions, BoxLayout.Y_AXIS));
Box box = Box.createVerticalBox();
box.add(Window.playS);
box.add(Box.createVerticalStrut(20));
box.add(Window.playM);
box.add(Box.createVerticalStrut(20));
box.add(Window.options);
box.add(Box.createVerticalStrut(20));
box.add(Window.language);
box.add(Box.createVerticalStrut(20));
box.add(Window.exit);
box.add(Box.createVerticalStrut(20));
pnlMenu.add(box);
pnlMenu.add(new JPanel());
pnlMenu.add(new JPanel());
pnlMenu.add(new JPanel());
pnlMenu.add(new JPanel());
pnlMenu2.add(Window.lblVersion);
System.out.println("Window class loaded");
}
And here is what my menu class currently looks like (this is what previously handled everything to do with the buttons and labels except their creation).
package menu;
import main.Window;
public class Menu
{
public Menu()
{
Listener listener = new Listener();
//Add ActionListeners
Window.exit.addActionListener(listener);
Window.playS.addActionListener(listener);
Window.playM.addActionListener(listener);
Window.options.addActionListener(listener);
Window.language.addActionListener(listener);
Window.btnBack.addActionListener(listener);
System.out.println("Menu class loaded");
}
}