英文:
Change JFrame size dynamically to JTable contents
问题
我又陷入了困境。
这次我在一个 JFrame
内部放置了一个 JTable
。
基本上,我希望在生成的表格下面没有“空白”。
当调整大小时,行的高度不会改变,但是由于某种原因,列的宽度会改变。是否有可能在下面没有白色空间?
如果可能的话,我希望不要有滚动条,只显示完整的表格,并且移除空白,这样即使调整大小,也不会显示出来。
快速更新:我使用了 gridlayout
布局,有点奏效,但是我的标题字体比表格要大,导致单元格能够正确显示,但标题被截断显示为“Hea...”。
英文:
I've got myself stuck again.
This time I have a JTable
inside a JFrame
.
I basically just want there to be no "white-space" below the table generated.
When resizing, the rows don't change height, but the columns change width for some reason. Is it at all possible to not have the white space below?
I'd prefer not to have a scrollbar if it at all possible, and just show the entire table with the white space removed, so even when resized, it doesn't show up.
Quick Update: i used the gridlayout layout and it kind of worked, but my header has a bigger font than the table, resulting in the cells to be shown properly, but the headers being cutoff and displayed as "Hea..."
答案1
得分: 1
> 是否有可能完全去除下方的空白?
JTable table = new JTable(model);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JScrollPane scrollPane = new JScrollPane(table);
frame.add(scrollPane);
frame.pack();
frame.setVisible(true);
英文:
> Is it at all possible to not have the whitespace below?
JTable table = new JTable(model);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JScrollPane scrollPane = new JScrollPane( table );
frame.add(scrollPane);
frame.pack();
frame.setVisible( true );
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论