java - 在 java 的 GUI 中,除了 .north、.south、.east、.west、.center 之外,我还能使用什么?
问题描述
add(banner, BorderLayout.NORTH);
add(bread, BorderLayout.CENTER);
add(sandwiches, BorderLayout.EAST);
add(drinks, BorderLayout.WEST);
add(buttonPanel, BorderLayout.SOUTH);
我目前有一个 GUI,并使用了这 5 个位置分配。如果我想在右侧添加另一个面板,是否可以使用另一个?
解决方案
我想在右侧添加另一个面板?
因此,您使用适当的布局管理器创建另一个子 JPanel:
JPanel east = new JPanel( new BorderLayout() );
east.add(sandwiches, BorderLayout.LINE_START);
JPanel anotherPanel = new JPanel( new GridLayout(0, 1) );
anotherPanel.add( new JButton("Button1") );
anotherPanel.add( new JButton("Button2") );
east.add(anotherPanel, BorderLayout.LINE_END);
//add(sandwiches, BorderLayout.EAST);
add(east, BorderLayout.EAST);
因此,“东”面板变成了一个嵌套面板,其中包含另外两个面板。
推荐阅读
- sql - ORA-00927: 缺少等号 Oracle SQL
- javascript - 无法将序列化数据返回到可引用的 json 对象中
- python - 如何在 python 中将多个 3 维数组更改为单个 4 维数组?
- python - python scrapy检查类是否存在否则检查其他
- django - 在不访问数据库的情况下使用“登录用户”测试视图
- python - 如何将特殊键添加到键盘记录器 python
- android - Dart 中如何从 Https 服务器获取数据
- r - 如何安排 Cronjob 以执行文件中的所有 R 脚本
- reactjs - React Hooks:如何正确干净地使用Ref().current
- talend - 如何与 Talend Job 建立多个连接?