ran*_*nzy 8 java layout user-interface swing
有没有办法在Java中使用多个布局管理器.现在我正在使用gridLayout来实现一个国际象棋棋盘但在它下面我想放一些其他的东西但不在gridLayout中.也许是FlowLayout或其他一些布局.我该怎么做呢?谢谢!
是的,您只需要计划您的所有UI布局(即;窗口,主面板等)
例如,你需要在棋盘下放一些东西,我通常会在基本级别使用BorderLayout.
所以假设我有一个名为masterPanel的JPanel,它包含我的国际象棋应用程序的所有组件.所以,代码看起来像:
JPanel masterPanel = new JPanel(new BorderLayout());
JPanel chessBoardPanel = createChessboardPanel(); //assuming this method will return a
//JPanel with chess board using GridLayout
JPanel infoPanel = new JPanel(); //this is the panel that would contain info elements, that //may go below my chess board.
//Now add everything to master panel.
masterPanel.add(chessBoardPanel, BorderLayout.CENTER);
masterPanel.add(infoPanel, BorderLayout.PAGE_END);
//add masterPanel to your window (if required)
this.getContentPane().add(masterPanel);
Run Code Online (Sandbox Code Playgroud)