찾다

 >  Q&A  >  본문

java - 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);
    }

求各位帮忙!!

天蓬老师天蓬老师2803일 전827

모든 응답(1)나는 대답할 것이다

  • PHPz

    PHPz2017-04-17 13:02:14

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

        groupListPanel.setMinimumSize(new Dimension(150, 480));
        personListPanel.setMinimumSize(new Dimension(150, 480));
        showPanel.setMinimumSize(new Dimension(300, 480));
    

    회신하다
    0
  • 취소회신하다