0

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);
  • The code which fills the table seems also relevant, because that code itself probably cannot reproduce what you are seeing. Please post a proper [mre] (ie stripped down runnable code). – gthanop Jul 30 '20 at 15:11
  • 1
    `contentPane.setLayout(null);` and `JScrollPane` don't go well together. Avoid the use of `null-layout`, it's [harmful](https://stackoverflow.com/questions/6592468/why-is-it-frowned-upon-to-use-a-null-layout-in-swing) for your application. You will run into this kind of issues you're having, or [this one](https://stackoverflow.com/a/42521097/2180785) and [this one](https://stackoverflow.com/a/63121986/2180785). For better help sooner post a proper [mre] that demonstrates your issue – Frakcool Jul 30 '20 at 15:14

1 Answers1

0

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

table.setFillsViewportHeight(true);

to make it fill the JScrollPane's viewport.