java - How to properly add textarea to tabbedpane -


i have assignment create multitab editor gedit .so have used jtabbedpane , added jtextarea in constructor . facing problem while using methods textarea.cut(); textarea textarea if user creates new tab user must able implement cut,copy,paste. used tabbedpane.getselectedcomponent().but says component cannot converted jtextarea used typecasted .the question not getting expected output i.e not adding tabs question how add these components tabbed pane in clean , efficient way. alternative methods of doing welcome.

here snippets of code.

         //components declared in class editor extends jframe         jtextarea textarea ;         jscrollpane scrollpane ;         jtabbedpane tabbedpane ;          public editor(){      this.setlayout(new flowlayout());     tabbedpane = new jtabbedpane();     tabbedpane.addtab("file",textarea);     add(tabbedpane);     scrollpane = new jscrollpane(tabbedpane);     getcontentpane().add(scrollpane, borderlayout.center);      //content in constructor     //also contains other components not shown here.     } //end constructor            //add new tabs           newfile = new jmenuitem("new file");            file.add(newfile);            newfile.addactionlistener(new actionlistener() {             @override             public void actionperformed(actionevent actionevent) {                    tabbedpane = new jtabbedpane();                    tabbedpane.addtab("file",textarea);                    add(tabbedpane);                   scrollpane = new jscrollpane(tabbedpane);                   getcontentpane().add(scrollpane, borderlayout.center);             }//end actionperformed            });//end method new              this.add(tabbedpane, borderlayout.center);                 //added cut jmenuitem menu edit added tojmenubar                    cut = new jmenuitem("cut");                 edit.add(cut);                 cut.addactionlistener(new actionlistener(){         public void actionperformed(actionevent actionevent){              jtextarea txtarea = new jtextarea();             txtarea = (jtextarea)tabbedpane.getselectedcomponent();                 txtarea.cut();          }//end actionperformed      });//end method cut 

tab key (tan name) should differ, , tabbedpane should add once.

//constructor public editor() {     tabs = new jtabbedpane(jtabbedpane.top, jtabbedpane.scroll_tab_layout);     add(tabs, borderlayout.center); }  //class method void addfile(string name) {     tabs.addtab(name, new jscrollpane(new textarea())); } 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -