watertonylzc
watertonylzc
2011-03-21 20:04
浏览 442
已采纳

在JSplitPane里添加JScrollPane,文本区的滚动条不出来,求教

将分割面板上下两部分都加上JScrollPane,再加上JTextArea,文本区不出现滚动条,该怎么办呢?求指教!

[code="java"]
public MainFrame(){
JScrollPane scpane1 =new JScrollPane();
JScrollPane scpane2 =new JScrollPane();
JTextArea ta1 =new JTextArea();
JTextArea ta2 =new JTextArea();
JSplitPane sppane_v = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
sppane_v.setDividerLocation(200);

    this.setBounds(300,200,300,600);
    this.setBackground(java.awt.Color.lightGray);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container cont = this.getContentPane();
        cont.add(sppane_v);
    sppane_v.setLeftComponent(scpane1.add(ta1));
    sppane_v.setRightComponent(scpane2.add(ta2));

    this.setVisible(true);
}

[/code]

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • changchanghust
    changchanghust 2011-03-21 22:01
    已采纳

    [code="java"]sppane_v.setLeftComponent(scpane1.add(ta1));

    sppane_v.setRightComponent(scpane2.add(ta2));[/code]

    改成

    [code="java"]sppane_v.setLeftComponent(new JScrollPane(ta1));

    sppane_v.setRightComponent(new JScrollPane(ta2)); [/code]

    试试看?

    点赞 1 评论

相关推荐