回 帖 发 新 帖 刷新版面

主题:[讨论]请教关于滚动条的问题!!

请问在第42行中,怎样编写关于JTextArea的滚动条??
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class lianxi extends JFrame
{
      lianxi(String Title)
      {
              super(Title);
              LianJie();
              WenBen(); 
      }
      JMenuBar jmenubar=new JMenuBar();
      JMenu[] jmenu=new JMenu[]{new JMenu("文件"),new JMenu("编辑")};
      JMenuItem[][] jmenuitem=new JMenuItem[][]{{new JMenuItem("新建"),new JMenuItem("打开"),new JMenuItem("保存"),new JMenuItem("退出")},
                                                {new JMenuItem("剪切"),new JMenuItem("复制"),new JMenuItem("粘贴"),new JMenuItem("删除")}};                             
        ActionListener action=new ActionListener()
                              {
                                      public void actionPerformed(ActionEvent e)
                                      {
                                            
                                      }
                              };
        public void LianJie()
        {
                int i,j;
                for(i=0;i<jmenu.length;i++)
                {
                    jmenubar.add(jmenu[i]);
                  for(j=0;j<jmenuitem[i].length;j++)
                  {
                          jmenu[i].add(jmenuitem[i][j]);
                          jmenuitem[i][j].addActionListener(action);
                  }
                }
                this.setJMenuBar(jmenubar);
        }
        public void WenBen()
        {
                JTextArea word=new JTextArea();
                this.getContentPane().add(word);
                       //     第42行
        }
        public static void main(String[] args)
        {
                lianxi L=new lianxi("菜单窗口");
                L.setSize(600,400);
                L.setLocation(180,180);
                L.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                L.setVisible(true);
        }
}

回复列表 (共2个回复)

沙发

Look at Swing JScrollPane. 

Read and see examples here:
[url]http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html[/url]

板凳

要想让JTextArea显示滚动条,就需要把JTextArea放入JScrollPane中。

public void WenBen()
{  
   JTextArea word=new JTextArea();
   JScrollPane sp = new JScrollPane(word);
   this.getContentPane().add(sp);
}

我来回复

您尚未登录,请登录后再回复。点此登录或注册