我有一个框架设置为:
setExtendedState(JFrame.MAXIMIZED_BOTH);
现在我有了一个 Jtable,并且在 eclipse 的设计阶段我已经完全适合框架了:
但是当我运行该程序时,右侧有很多浪费的空间,如下所示:
如何扩展它以填充右侧的空白空间?
最佳答案
要使 JTable
填充可用空间,请将其放入具有 BorderLayout
布局管理器的 JPanel
中。
JTable table = new JTable();
// Set up table, add data
yourFrame.getContentPane().add( new JScrollPane( table ), BorderLayout.CENTER );
更新:按照camickr的建议
you don't need the getContentPane(). Since JDK4 you can just add components directly to the frame and then will be added to the content pane automatically.
yourFrame.add( new JScrollPane( table ), BorderLayout.CENTER
关于java - 如何使 JTable 适合 JFrame 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29373180/