java - 如何在 Swing 中创建一个有组织的信息“列表”的面板
问题描述
我正在尝试创建一个包含信息的面板。
我尝试使用 将setBorderLayout
带有信息的标签添加到面板的某些区域,但我知道这不起作用,因为它只会覆盖我之前已经拥有的内容。
这是我的代码中的一个示例:
final JFrame fr = new JFrame("ATCGUI");
fr.setLayout(new BorderLayout());
JTabbedPane tabbedPane = new JTabbedPane();
JPanel tab1 = new JPanel();
tab1.setLayout(new BorderLayout());
tabbedPane.addTab("Airport", tab1);
JLabel labelAirportName = new JLabel(airportInfo[0]);
tab1.add(labelAirportName, BorderLayout.NORTH);
JLabel labelAirportCodeStatic = new JLabel("Code:");
JLabel labelAirportLocationStatic = new JLabel("Location:");
JLabel labelAirportCoordinatesStatic = new JLabel("Coordinates:");
JLabel labelAirportAltitudeStatic = new JLabel("Altitude:");
JLabel labelAirportTimezoneStatic = new JLabel("Timezone:");
JLabel labelAirportICAOStatic = new JLabel("ICAO:");
tab1.add(labelAirportCodeStatic, BorderLayout.WEST);
tab1.add(labelAirportLocationStatic, BorderLayout.WEST);
tab1.add(labelAirportCoordinatesStatic, BorderLayout.WEST);
tab1.add(labelAirportAltitudeStatic, BorderLayout.WEST);
tab1.add(labelAirportTimezoneStatic, BorderLayout.WEST);
tab1.add(labelAirportICAOStatic, BorderLayout.WEST);
这最终创建了这样的东西:
当我的目标是看起来更像这样的东西时:
我用 SwingUI 设计器创建了这个,但由于兼容性,我只切换到 Swing
解决方案
按照 maloomeister 链接的 Oracle Swing 教程https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
通过混合 BorderLayout 和 GridLayout,我能够创建我想要的布局。
推荐阅读
- python - 为什么即使该列名确实存在,Pandas 也不让我选择数据框中的特定列?
- c# - 如何从WPF中的另一个窗口编辑窗口的内容
- excel - 如何使用 .Find 设置 Range 变量?
- android - ListView.builder 小部件不滚动
- javascript - 将属性分配给精灵及其主体
- android - 我应该将 viewModelScope.coroutineContext 传递给 liveData 构建器函数吗?
- neural-network - Unet 预测灰度图像(灰块)
- ajax - Laravel ajax 表单调用 jQuery 函数
- c++ - std::promise 的存储
:“通信对象” - c - 在 C 中使用指针连接字符串