Reputation: 15099
So I have a bunch of JTable
s. Each JTable
is inside a JScrollPane
. I'm then adding each of these JScrollPane
s to a JPanel
. I'm then adding this JPanel
to a JScrollPane
then that to another JPanel
with BorderLayout
. The larger JScrollPane
properly resizes with its parent, but each of the smaller JScrollPane
s have constant height, which is larger than the window when it is small. How can I get each of the children JScrollPane
s to resize with the height of the window/their parent?
I've tried adding more intermediary JPanel
s with FlowLayout
, BorderLayout
, and nothing seems to work.
Here's some relevant 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 really 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 that stuff to resize appropriately when the window size changes.
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
Upvotes: 1
Views: 968
Reputation: 109547
You can use a BoxLayout. If you want the opposite: some table being fixed, you can wrap it with constraint Box.createRigidArea(new Dimension(100, 100)) .
Upvotes: 2