【发布时间】:2015-10-10 21:33:14
【问题描述】:
我创建了按钮和 jlist。我所有的按钮都在另一个名为 buttonPanels 的面板中,我想将该面板和 jList 添加到另一个名为 jPanelSouth 的面板中。我尝试使用 ______.setLocation(x,y) 来定位我的按钮,但按钮似乎没有在面板内的任何位置移动(与 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);
我不确定在这种情况下我应该使用什么布局
【问题讨论】:
-
你可以使用 GridBagLayout
-
谢谢,这真的很有帮助。我什至不知道 GridBagLayout
标签: java swing layout layout-manager panels