최근 Java에서 UI 개발을 시작했습니다. WPF에서 UI 개발을 해왔습니다. Java 수행 방법에 대한 몇 가지 사항이 혼란 스럽습니다.BoxLayout이있는 JPanel 내부 JButton의 크기가 예상대로 작동하지 않습니다.
내가 달성하고자하는 것은 버튼의 최소 크기를 설정하는 것입니다. 컨테이너가 폭 200 개 픽셀을 할당됩니다 경우
가public class MainGameView extends JPanel {
public MainGameView(DefaultController controller) {
this.controller = controller;
CreateUI();
}
private void CreateUI() {
MenuPanel = new javax.swing.JPanel();
StartGameBtn = new JButton("Start Game");
// Creating menu
MenuPanel.setLayout(new BoxLayout(MenuPanel, BoxLayout.Y_AXIS));
MenuPanel.setPreferredSize(new Dimension(200, 200));
StartGameBtn.setAlignmentX(Component.LEFT_ALIGNMENT);
StartGameBtn.setMinimumSize(new Dimension(200, 30));
MenuPanel.add(StartGameBtn);
}
}
내 이해 그래서, 그에 따라 버튼에 폭 200 개 픽셀을 할당해야합니다 다음은 간단한 코드입니다. 그러나 버튼은 동일한 크기를 유지합니다. 내가 여기서 뭔가를 놓치고 있니?