日期:2014-05-20  浏览次数:20628 次

JSplitPane问题
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Example10_10 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
EditWindow win=new EditWindow("窗口");

}
}
class EditWindow extends JFrame implements ActionListener{
JMenuBar menubar;
JMenu menu;
JSplitPane splitPane;
JMenuItem itemCopy,itemCut,itemPaste;
JTextArea text1,text2;
EditWindow(String s){
setTitle(s);
setSize(260,270);
setLocation(120,120);
setVisible(true);
menubar=new JMenuBar();
menu=new JMenu("编辑");
itemCopy=new JMenuItem("复制");
itemCut=new JMenuItem("剪切");
itemPaste=new JMenuItem("粘贴");
menu.add(itemCopy);
menu.add(itemCut);
menu.add(itemPaste);
menubar.add(menu);
setJMenuBar(menubar);
text1=new JTextArea();
text2=new JTextArea();
  text1.setLineWrap(true);
  text2.setLineWrap(true);
  add(text1);
  add(text2);
splitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,text1,text2);
splitPane.setDividerLocation(120);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
validate();
itemCopy.addActionListener(this);
itemCut.addActionListener(this);
itemPaste.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==itemCopy)
text1.copy();
else if(e.getSource()==itemCut)
text1.cut();[code=Java][/code]
else if(e.getSource()==itemPaste);
text2.paste();
 
}
 
}
为什么运行后,只显示窗体,没有显示窗体中的分割线,为什么添加了两个JTextArea组件,却一个也不显示,JSplitPane的用法对吗?谁能帮我解释一下,谢谢!



------解决方案--------------------
设置布局
------解决方案--------------------
jsplitpane也要添加到jframe的contentpane。
------解决方案--------------------
this.add(splitPane);构造函数加上这段代码,splitPane你没有加进来啊
------解决方案--------------------
探讨
this.add(splitPane);构造函数加上这段代码,splitPane你没有加进来啊