JTextpane 无法正常显示, 把整个JFrame都占满了

新手上路,请多包涵

我本来希望JFrame 按这样显示图片描述
可是当我在绿色的panel中加入JTexpane并附上文字之后就变成了这样
图片描述
下面是我打代码

public static void main(String[] args){
        JFrame frame = new JFrame();
        frame.setLayout(new GridBagLayout());
        JPanel groupListPanel = new JPanel();


        // init component
        JPanel personListPanel = new JPanel();
        JPanel showPanel = new JPanel(new BorderLayout());
        groupListPanel.setBackground(Color.red);
        personListPanel.setBackground(Color.yellow);
        showPanel.setBackground(Color.green);
        // add a textpane
        JTextPane pane = new JTextPane();
        // setText
        pane.setText("亩产万斤亩产万斤亩产万斤亩产万斤亩产万斤亩产万斤\n亩产万斤亩产万斤亩产万\n斤亩产万斤亩\n产万斤亩产万斤亩产万斤亩产万斤亩产万斤亩产万斤亩产万斤亩\n产万斤亩产万斤\n亩产万斤斤亩产万斤亩产万斤亩产万斤亩产万斤亩产万斤亩产斤亩产万斤亩产万斤亩产万斤亩产万斤亩产万斤亩产斤亩产万斤亩产万斤亩产万斤亩产万斤亩产万斤亩产斤亩产万斤亩产万斤亩产万斤亩产\n万斤亩产万斤亩产");
        //pane.setText("afjiwof\nwjfie\nw\n");
        showPanel.add(pane, BorderLayout.CENTER);
        JPanel ListPanel = new JPanel(new FlowLayout()); 
        ListPanel.add(groupListPanel);
        ListPanel.add(personListPanel);

        frame.add(groupListPanel, new GridBagConstraints(0,1,1, 1,0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0),0,0));
        frame.add(personListPanel, new GridBagConstraints(1,1,1,1,0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0),0,0));
        //frame.add(new JPanel(), new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        frame.add(showPanel, new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0,0,0,0), 0, 0));

        groupListPanel.setPreferredSize(new Dimension(144, 507));
        personListPanel.setPreferredSize(new Dimension(144, 507));
        frame.setPreferredSize(new Dimension(674, 582));
        frame.setSize(new Dimension(674, 582));
        frame.setVisible(true);
    }

求各位帮忙!!

阅读 4.1k
1 个回答

添加文字那行后面加上这几句:

    groupListPanel.setMinimumSize(new Dimension(150, 480));
    personListPanel.setMinimumSize(new Dimension(150, 480));
    showPanel.setMinimumSize(new Dimension(300, 480));
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题