有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何在java swing表单配置文件中显示动态布局

 <Panel AutoScroll ="false" AutoSize="true" Column="2" ColumnSpan="3" Row="4" RowSpan="1" Category="INPUT">
      <MaximumSize Height="0" Width="0"/>
      <MinimumSize Height="0" Width="0"/>
      ...
      <Size Height="120" Width="389"/>
      ...
      <CellBorderStyle>None</CellBorderStyle>
      <Dock>Left</Dock>
      <Anchor>Top,Left</Anchor>

    </Panel>

我在配置文件中有一个元素: 我想在JavaSwing中加载一个JPanel。在java中,我设置

GridBagConstraints layout = new GridBagConstraints();    
layout.fill = GridBagConstraints.VERTICAL;
layout.anchor = GridBagConstraints.WEST;

在Jpanel中,我看到面板和面板中的控件都向左移动。但是属性ColumnSpan=“3”。 我希望面板将填满,因此我使用:

layout.fill = GridBagConstraints.BOTH;
layout.anchor = GridBagConstraints.WEST;

当面板中的所有控件都充满时

谁能帮我解决这个问题

我的代码:

loadDynamicPanel(List<PanelType> pannels, JPanel mainPanel, JFramFram form)
    {
        JPanel tempPanel = null;
        for (int j = 0; j < pannels.size(); j++)
        {
            PanelType panelType = pannels.get(j);
            tempPanel = new JPanel(new GridBagLayout());

            layout.fill = GridBagConstraints.VERTICAL;
            layout.anchor = GridBagConstraints.WEST;

            layout.gridx = panelType.getColumn() != null ? panelType.getColumn() : 0;
            layout.gridy = panelType.getRow() != null ? panelType.getRow() : 0;
            layout.gridheight =  panelType.getRowSpan();
            layout.gridwidth =panelType.getColumnSpan();        

            TitledBorder border = new TitledBorder(new LineBorder(Color.BLACK, 1));

            tempPanel.setBorder(border);

            tempPanel.setSize(panelType.getSize().getWidth(), panelType.getSize().getHeight());

            mainPanel.add(tempPanel, layout);
        }
    }

共 (0) 个答案