Search code examples
javajbuttonborder-layout

BorderLayout Left Assignment


I have a JPanel with BorderLayout and some Buttons on SOUTH. When I add the Buttons they are in the middle. But I want them to be on the left.

Is that possible?


Solution

  • From: http://docs.oracle.com/javase/7/docs/api/java/awt/BorderLayout.html

    Each region may contain no more than one component, and is identified by a corresponding constant: NORTH, SOUTH, EAST, WEST, and CENTER.

    Panel p = new Panel();
    p.setLayout(new BorderLayout());
    p.add(new Button("Okay"), BorderLayout.WEST);
    

    Create a JPanel with a BorderLayout, add this panel to SOUTH position of the main panel. Create another JPanel, add your buttons to this panel (using what ever layout manager you need. Now add the "button" panel to the south panel at the WEST position