我本来希望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);
}
求各位帮忙!!
Add these sentences after the line to add text: