JTable被锁定在JScrollPane的顶部

huangapple go评论69阅读模式
英文:

JTable Locked at the Top of the JScrollPane

问题

我正在使用WindowBuilder创建一个GUI应用程序。因此,我放置了一个JTable,右键单击,然后单击"用JScrollPane包围"。然后,我将JScrollPane拖动到JTabbedPane中,以便我可以在选项卡中使用它。然而,JTable被锁定在顶部,角落的调整大小锚点不起作用,JTable没有高度。JScrollPane的大小是正确的,但JTable却停留在顶部,高度为0。当JScrollPane在JTabbedPane之外时,也会出现这个问题。

代码的相关部分:

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 850, 650);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
		
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
tabbedPane.setBounds(10, 11, 814, 578);
contentPane.add(tabbedPane);
		
JScrollPane scrollPane = new JScrollPane();
tabbedPane.addTab("New tab", null, scrollPane, null);
		
		
table = new JTable();
scrollPane.setViewportView(table);
setVisible(true);
英文:

I am using WindowBuilder to create a GUI application. So, I placed a JTable, right clicked, and click surround with JScrollPane. I then dragged the JScrollPane to go into a JTabbedPane so that I could use it in a tab. However, the JTable is locked at the top, the resize anchors at the corners aren't working, and there is no height to the JTable. The JScrollPane is correctly sized, but the JTable is stuck at the top with a height of 0. This issue also occurs when the JScrollPane is outside of the JTabbedPane.

Relevant portion of the code:

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 850, 650);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
		
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
tabbedPane.setBounds(10, 11, 814, 578);
contentPane.add(tabbedPane);
		
JScrollPane scrollPane = new JScrollPane();
tabbedPane.addTab("New tab", null, scrollPane, null);
		
		
table = new JTable();
scrollPane.setViewportView(table);
setVisible(true);

</details>


# 答案1
**得分**: 0

我解决了这个问题我必须添加这一行

table.setFillsViewportHeight(true);

以使其填充JScrollPane的视口

<details>
<summary>英文:</summary>

I solved the problem. I had to add this line:

    table.setFillsViewportHeight(true);
to make it fill the JScrollPane&#39;s viewport.

</details>



huangapple
  • 本文由 发表于 2020年7月30日 22:50:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/63175761.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定