swing - Unable to make text areas uneditable in java -
i pretty new java, , i'm learning how make guis. test out making them, tried making 1 on own. in order find out how make text boxes uneditable, googled , found on oracle website , tried out. unfortunately when attempt execute this, given errors 'syntax error on token(s), misplaced construct(s)' , 'syntax error on token "false", delete token'. had far text area:
jtextarea textarea = new jtextarea("testing text", 5, 10); jscrollpane scrollpane = new jscrollpane(textarea); textarea.seteditable(false);
the error @ period between 'textarea' , 'seteditable' , (of course) 'false'. same kind of error when try settext.
if helps, imported was:
import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.joptionpane; import javax.swing.jpanel; import javax.swing.jtextfield; import javax.swing.jtextarea; import javax.swing.jscrollpane; import java.awt.event.actionevent; import java.awt.event.actionlistener;
i extended jframe , implemented actionlistener
any appreciated :)
so upon request, posting rest of code here. unfortunately haven't gotten far in program yet, post have far , try finish soon.
runtestgui.java file:
import javax.swing.jframe; public class runtestgui { public static void main(string[] args) { // todo auto-generated method stub testgui gui = new testgui(); gui.setdefaultcloseoperation(jframe.exit_on_close); } }
testgui.java file:
/*import java.awt.event.actionevent; import java.awt.event.actionlistener;*/ //import javax.swing.*; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.joptionpane; import javax.swing.jpanel; import javax.swing.jtextfield; import javax.swing.jtextarea; import javax.swing.jscrollpane; //import java.awt.event.actionevent; //import java.awt.event.actionlistener; public class testgui extends jframe /*implements actionlistener*/ { //global components jtextarea textarea = new jtextarea("testing text", 5, 10); jscrollpane scrollpane = new jscrollpane(textarea); textarea.seteditable(false); jtextfield textbox; //constructor testgui(string title){ super(title); this.init(); this.pack(); this.setvisible(true); }//end constructor public void init(){ jlabel ltextbox = new jlabel("textbox: "); textbox = new jtextfield(10); jpanel leftpanel = new jpanel(); leftpanel.add(ltextbox); leftpanel.add(textbox); jpanel rightpanel = new jpanel(); rightpanel.add(textarea); } }
problem have put line textarea.seteditable(false);
in method body, either can put in constructor or method:
public void init(){ jlabel ltextbox = new jlabel("textbox: "); textbox = new jtextfield(10); jpanel leftpanel = new jpanel(); leftpanel.add(ltextbox); leftpanel.add(textbox); jpanel rightpanel = new jpanel(); rightpanel.add(textarea); textarea.seteditable(false); //<-- put here }
Comments
Post a Comment