java - Can't append/ add text to a jTextArea -
i'm trying build application has console text-area, can't text either appended or added text inside jtextarea. wondering if me work out why code showing no errors?
code follows:
form 1:
package com.company; public class form1 extends javax.swing.jframe { private javax.swing.jbutton btncombobox; private javax.swing.jcombobox<string> comboone; private javax.swing.jlabel jlabel2; private javax.swing.jlabel jlabel3; public form1() { initcomponents(); } @suppresswarnings("unchecked") private void initcomponents() { jlabel2 = new javax.swing.jlabel(); comboone = new javax.swing.jcombobox<>(); jlabel3 = new javax.swing.jlabel(); btncombobox = new javax.swing.jbutton(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); jlabel2.sethorizontalalignment(javax.swing.swingconstants.center); jlabel2.settext("select printer:"); comboone.setmodel(new javax.swing.defaultcomboboxmodel<>(new string[] { "printer 1", "printer 2", "printer 3", "printer 4" })); comboone.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { combooneactionperformed(evt); } }); jlabel3.setfont(new java.awt.font("tahoma", 1, 11)); jlabel3.settext("zebra printer "); btncombobox.settext("go"); btncombobox.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { btncomboboxactionperformed(evt); } }); javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(javax.swing.grouplayout.alignment.trailing, layout.createsequentialgroup() .addcontainergap(154, short.max_value) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing) .addcomponent(jlabel3, javax.swing.grouplayout.preferred_size, 90, javax.swing.grouplayout.preferred_size) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.trailing, false) .addcomponent(comboone, javax.swing.grouplayout.alignment.leading, 0, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jlabel2, javax.swing.grouplayout.alignment.leading, javax.swing.grouplayout.default_size, 93, short.max_value) .addcomponent(btncombobox, javax.swing.grouplayout.alignment.leading, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value))) .addgap(153, 153, 153)) ); layout.setverticalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addcontainergap() .addcomponent(jlabel3) .addgap(18, 18, 18) .addcomponent(jlabel2) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addcomponent(comboone, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size) .addgap(18, 18, 18) .addcomponent(btncombobox) .addcontainergap(176, short.max_value)) ); pack(); } private void combooneactionperformed(java.awt.event.actionevent evt) { object selected = comboone.getselecteditem().tostring(); } private void btncomboboxactionperformed(java.awt.event.actionevent evt) { // opens new form, converts object selected in combobox string // passes string openme on form 2 form2 f2 = new form2(); f2.openme(comboone.getselecteditem().tostring()); this.setenabled(false); } public static void main(string args[]) { try { (javax.swing.uimanager.lookandfeelinfo info : javax.swing.uimanager.getinstalledlookandfeels()) { if ("nimbus".equals(info.getname())) { javax.swing.uimanager.setlookandfeel(info.getclassname()); break; } } } catch (classnotfoundexception ex) { java.util.logging.logger.getlogger(form1.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (instantiationexception ex) { java.util.logging.logger.getlogger(form1.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (illegalaccessexception ex) { java.util.logging.logger.getlogger(form1.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (javax.swing.unsupportedlookandfeelexception ex) { java.util.logging.logger.getlogger(form1.class.getname()).log(java.util.logging.level.severe, null, ex); } java.awt.eventqueue.invokelater(new runnable() { public void run() { new form1().setvisible(true); } }); } }
form 2:
package com.company; public class form2 extends javax.swing.jframe { private javax.swing.jlabel jlabel1; private javax.swing.jlabel jlabel3; private javax.swing.jscrollpane jscrollpane2; private javax.swing.jtextarea jta; public form2() { initcomponents(); jta.append("----- console output ------\n"); jta.append("----------------------------------"); } @suppresswarnings("unchecked") private void initcomponents() { jlabel1 = new javax.swing.jlabel(); jlabel3 = new javax.swing.jlabel(); jta = new javax.swing.jtextarea(); jscrollpane2 = new javax.swing.jscrollpane(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); jlabel1.settext("console"); jlabel3.setfont(new java.awt.font("tahoma", 1, 11)); jlabel3.settext("zebra printer "); jta.setcolumns(20); jta.setrows(5); jscrollpane2.setviewportview(jta); javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addcontainergap() .addcomponent(jlabel1)) .addgroup(layout.createsequentialgroup() .addgap(158, 158, 158) .addcomponent(jlabel3))) .addgap(0, 192, short.max_value)) .addgroup(layout.createsequentialgroup() .addcontainergap() .addcomponent(jscrollpane2))) .addcontainergap()) ); layout.setverticalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgap(12, 12, 12) .addcomponent(jlabel3) .addgap(17, 17, 17) .addcomponent(jlabel1) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addcomponent(jscrollpane2, javax.swing.grouplayout.default_size, 276, short.max_value) .addcontainergap()) ); pack(); } public void openme(string message) { try { (javax.swing.uimanager.lookandfeelinfo info : javax.swing.uimanager.getinstalledlookandfeels()) { if ("nimbus".equals(info.getname())) { javax.swing.uimanager.setlookandfeel(info.getclassname()); break; } } } catch (classnotfoundexception ex) { java.util.logging.logger.getlogger(form2.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (instantiationexception ex) { java.util.logging.logger.getlogger(form2.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (illegalaccessexception ex) { java.util.logging.logger.getlogger(form2.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (javax.swing.unsupportedlookandfeelexception ex) { java.util.logging.logger.getlogger(form2.class.getname()).log(java.util.logging.level.severe, null, ex); } java.awt.eventqueue.invokelater(new runnable() { public void run() { new form2().setvisible(true); new form1().setvisible(false); } }); system.out.println("----- console output ------"); system.out.println("---------------------------"); system.out.println("printer selected: "+ message); system.out.println("---------------------------"); system.out.println("\n"); jta.settext(message); jta.append("printer selected:"+message); } }
any appreciated always.
Comments
Post a Comment