java - JTextpane 无法正常显示, 把整个JFrame都占满了
天蓬老师
天蓬老师 2017-04-17 13:00:14
0
1
830

我本来希望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);
    }

求各位帮忙!!

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

répondre à tous(1)
PHPzhong

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

    groupListPanel.setMinimumSize(new Dimension(150, 480));
    personListPanel.setMinimumSize(new Dimension(150, 480));
    showPanel.setMinimumSize(new Dimension(300, 480));
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal