Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中的多布局管理器_Java_User Interface_Swing_Layout - Fatal编程技术网

Java中的多布局管理器

Java中的多布局管理器,java,user-interface,swing,layout,Java,User Interface,Swing,Layout,有没有办法在Java中使用多个布局管理器。现在我正在使用gridLayout来实现一个国际象棋棋盘,但在它下面我想放一些其他的东西,但不是在gridLayout中。可能是流程布局或其他布局。我该怎么做呢? 谢谢 有没有办法使用多个布局 Java中的管理器 当然。事实上,使用多个布局管理器是常态 我该怎么做呢 任何容器子类都可以有一个布局管理器并包含子元素。每个子元素本身都可以是一个包含子元素的容器。顶层框架下面最常用的容器是JPanel 例如,您可能应该为框架使用BorderLayout,放置一

有没有办法在Java中使用多个布局管理器。现在我正在使用gridLayout来实现一个国际象棋棋盘,但在它下面我想放一些其他的东西,但不是在gridLayout中。可能是流程布局或其他布局。我该怎么做呢? 谢谢

有没有办法使用多个布局 Java中的管理器

当然。事实上,使用多个布局管理器是常态

我该怎么做呢

任何
容器
子类都可以有一个
布局管理器
并包含子元素。每个子元素本身都可以是一个包含子元素的容器。顶层框架下面最常用的容器是
JPanel

例如,您可能应该为框架使用
BorderLayout
,放置一个
JPanel
,使网格位于其中心位置(因为当其他位置已指定其首选大小时,这是一个可以获得所有可用剩余空间的布局),另一个
JPanel
放置“其他东西”在南方的位置


更多详细信息可在中找到。

是的,您只需规划您的全面UI布局(即窗口、主面板等)

例如,你需要在你的棋盘下放置一些东西,我通常会在基本级别使用边界布局

假设我有一个名为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);