Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Add data from J...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 15952 of 16566
Post > Topic >>

Add data from Jlist to file

by CBO <christopher_board@[EMAIL PROTECTED] > Apr 10, 2008 at 02:40 AM

Hi all,

I am currently developing a java application that has a combo box and
when the user presses a button to delete an item out of the JList I
would like the data that is left inside the combo box to be written to
a CSV file so all the computer names go down in a column and not in a
row which is what it is doing currently. Below is the code I am using
in order to do this:

int index = lstComputerExceptions.getSelectedIndex();
          model.remove(index);

          int size = model.getSize();

          if (size == 0) { //Nobody's left, disable firing.
              btnDelete.setEnabled(false);

          } else { //Select an index.
              if (index == model.getSize()) {
                  //removed item in last position
                  index--;
              }

              lstComputerExceptions.setSelectedIndex(index);
              lstComputerExceptions.ensureIndexIsVisible(index);
              String computerName = model.toString();
              StringTokenizer st = new StringTokenizer(computerName,
"[,");
              st.nextToken();
              String computer = st.nextToken();


              try {
      	        BufferedWriter out = new BufferedWriter(new
FileWriter("C:\\Do***ents and Settings\\All Users\\Application Data\
\Remote Shutdown\\ExceptionsListTemp.csv"));
      	        out.write(computer);
      	        out.close();
//      	        initiateComputerList();
      	    } catch (IOException ex) {
      	    	System.err.println("Failed to add information to file");
      	    	statusBar.setForeground(Color.red);
      	    	statusBar.setText("Failed to add " +
txtComputerName.getText());
      	    }
              }

Any help in this matter would be highly appreciated.

Thank you
 




 2 Posts in Topic:
Add data from Jlist to file
CBO <christopher_board  2008-04-10 02:40:07 
Re: Add data from Jlist to file
RedGrittyBrick <RedGri  2008-04-10 11:56:10 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 16:28:12 CST 2008.