使用Java swing编写一个小工具时遇到一个问题
界面如下:
红框中的内容是一个JPanel,代码如下
- panel_9 = new JPanel();
- panel_9.setLayout(new GridLayout(1, 3));
- panel_9.setBorder(new LineBorder(Color.GREEN));
- GridBagConstraints gbc_panel_9 = new GridBagConstraints();
- gbc_panel_9.anchor = GridBagConstraints.WEST;
- gbc_panel_9.insets = new Insets(0, 0, 5, 5);
- gbc_panel_9.fill = GridBagConstraints.VERTICAL;
- gbc_panel_9.gridx = 2;
- gbc_panel_9.gridy = 1;
- panel_8.add(panel_9, gbc_panel_9);
但是当下面的JScrollPane 有滚动条时panel就自动缩小了,如下图
解决方法:
把panel的 gbc_scrollPane_1.fill 由GridBagConstraints.VERTICAL改为GridBagConstraints.BOTH
时间: 2024-11-02 19:17:06