开发者

JScrollPane inside BorderLayout.CENTER doesn't resize

开发者 https://www.devze.com 2023-04-12 20:18 出处:网络
This is the code below, the problem is that the JScrollPane stays at its preferred size and doesn\'t resize with the BorderLayout.CENTER region. I want it to fill that region, of course.. and use it t

This is the code below, the problem is that the JScrollPane stays at its preferred size and doesn't resize with the BorderLayout.CENTER region. I want it to fill that region, of course.. and use it to scroll the contents of the table inside it.

frame = new JFrame();
frame.setBounds(100, 100, 500, 400);
JPanel panelCenter = new JPanel();
FlowLayout flowLayout = (FlowLayout) panelCenter.getLayout();
flowLayout.setAlignment(FlowLayout.LEFT);
panelCenter.setPreferredSize(new Dimension(300, 400));

panelRight = new ActorDrawer();
fr开发者_JAVA百科ame.getContentPane().add(panelRight, BorderLayout.EAST);
panelRight.setLayout(null);
panelRight.setPreferredSize(new Dimension(200, 400));
frame.getContentPane().add(panelCenter, BorderLayout.CENTER);

table = new JTable(new MyTableModel());
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JScrollPane scrollPane = new JScrollPane(table);
table.setFillsViewportHeight(true);
panelCenter.add(scrollPane);


You don't add the JScrollPane to the center of the panel with the BorderLayout: you add it to another panel, with a FlowLayout, and this panel is added to the center. Remove the panelCenter.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号