如何使JTable填充整个可用空间? [英] How to make a JTable fill entire available space?
本文介绍了如何使JTable填充整个可用空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个带有表的面板,该表填充整个可用空间.
I want to created a panel with a table, which fills the entire available space.
我使用以下代码执行此操作:
I do this using following code:
public class MyFrame extends JFrame {
public EconomyFrame() throws HeadlessException {
super("...");
final JTabbedPane tabbedPane = new JTabbedPane();
add(tabbedPane);
final JPanel companiesPanel = new JPanel();
final CompaniesTableModel companiesModel = new CompaniesTableModel
(ApplicationStateSingleton.INSTANCE.getPersistence().getCompanies());
final JTable companiesTable = new JTable(companiesModel);
ApplicationStateSingleton.INSTANCE.getEventBus().subscribeToPropertyChanges(companiesModel);
companiesPanel.add(new JScrollPane(companiesTable));
tabbedPane.addTab("Companies", companiesPanel);
}
}
但是它不起作用,因为当我调整框架大小时,表格仅填充了可用空间的一部分(请参见下面的屏幕截图).
But it doesn't work because when I resize the frame, the table fills only part of the available space (see screenshots below).
我该如何解决(使表格填满整个可用空间)?
How can I fix (make the table fill the entire available space) ?
推荐答案
使用布局管理器,该管理器允许JTable
占据整个可用区域,而不是JPanel
使用的默认FlowLayout
(仅使用其首选组件)尺寸
Use a layout manager that allows the JTable
occupy the full area available rather than the default FlowLayout
used by JPanel
which only uses its components preferred sizes
JPanel companiesPanel = new JPanel(new GridLayout());
这篇关于如何使JTable填充整个可用空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文