How to get JScrollPanes inside JScrollPane to resize the parent element

So I have a bunch of JTable s. Each JTable is inside a JScrollPane . Then I add each of these JScrollPane to the JPanel . Then I add this JPanel to JScrollPane , and then to another JPanel with BorderLayout . The larger JScrollPane correctly with the parent, but each of the smaller JScrollPane has a constant height, which is larger than the window when it is small. How can I get each of the JScrollPane children to resize with the window / parent height?

I tried adding more intermediate JPanel with FlowLayout , BorderLayout , and nothing works.

Here is the code:

 public class MyPanel extends JPanel { public MyPanel() { super(new BorderLayout()); JPanel panel = new JPanel(); for (int i = 0; i < 5; i++) { // View extends JTable panel.add(new JScrollPane(new View(new Model()))); } add(new JScrollPane(panel)); } } 

I'm just trying to get a bunch of tables with scrollbars horizontally next to each other inside a larger panel with a horizontal scrollbar. And I want all these things to change accordingly when the window is resized.

more code:

 final MyPanel panel = new MyPanel(); final JTabbedPane tabView = new JTabbedPane(); tabView.add(...); tabView.add("foo", panel); final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, ..., tabView); this.add(splitPane); // this extends JFrame 
+1
source share
1 answer

You can use BoxLayout . If you want the opposite: some table is fixed, you can wrap it with the Box.createRigidArea restriction (new dimension (100, 100)) .

+2
source

Source: https://habr.com/ru/post/1491141/


All Articles