Java中的多个布局管理器 [英] Multiple Layout Managers in Java

查看:248
本文介绍了Java中的多个布局管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Java中使用多个布局管理器。现在我正在使用gridLayout来实现一个国际象棋棋盘,但在它之下我想放一些其他东西但不在gridLayout中。可能是FlowLayout或其他一些布局。我该怎么做呢?
谢谢!

Is there way to use more than 1 layout manager in Java. Right now I'm using a gridLayout to implement a chess board but beneath it I would like to put some other stuff but not in a gridLayout. Maybe a FlowLayout or some other layout. How would I go about doing this? Thanks!

推荐答案

是的,您只需要规划您的所有UI布局(即;窗口,主人)小组等)

Yes, all you need is to plan your over all UI Layout (i.e; Window, master panel etc)

例如,你需要在棋盘下放一些东西,我通常会在基本级别使用BorderLayout。

For example, you need to put something under your chessboard, I would normally go with a BorderLayout at the basic level.

假设我有一个名为masterPanel的JPanel,它包含我的国际象棋应用程序的所有组件。
因此,代码看起来像:

So assume I have a JPanel called masterPanel, that holds all the components for my chess app. So, code would look like:

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);

这篇关于Java中的多个布局管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆