0

I created buttons and a jlist. All my buttons are in another panel called buttonPanels, and I wanted to add that panel and the jList to another panel called jPanelSouth. I tried positioning my buttons by using the ______.setLocation(x,y) but the buttons don't seem to move anywhere within the panel (same with jlist).

 //southPanel and stuff
  jPanelSouth = new JPanel();
  jPanelSouth.setBorder(BorderFactory.createLineBorder(Color.black, 5));

  //buttons
  buttonPanel = new JPanel(new GridLayout(3,1));
  drawCardBtn = new JButton("Draw Card");
  moveBtn = new JButton("Move");
  playCardBtn = new JButton("Play Card");


  buttonPanel.add(drawCardBtn);
  buttonPanel.add(moveBtn);
  buttonPanel.add(playCardBtn);

  roomList = new JList(roomNumbers);
  roomList.setVisibleRowCount(4);
  roomList.setFixedCellWidth(100);
  roomList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);


  jPanelSouth.add(buttonPanel);
  jPanelSouth.add(roomList);

This is how my window looks right now

This is how I want it to look like

I'm not really sure what layout I should be using in this case

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Jake
  • 313
  • 1
  • 7
  • 16

2 Answers2

0

You should change a layout in your jPanelSouth. For example, try add this line to your code.

jPanelSouth.setLayout(new BoxLayout(jPanelSouth, BoxLayout.Y_AXIS));

Read some more about swing layouts here.

Mateusz Korwel
  • 1,118
  • 1
  • 8
  • 14
-2

Try using the setBounds( x, y, height, width) in your buttons.

buttonPanel = newJPanel();
buttonPanel.setBounds(x, y, height, width);
Staver
  • 63
  • 8
  • 1
    Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Oct 10 '15 at 22:38