Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

help: jComboBox

tollitolli Posts: 44Member
hi guys....wanna make sure my code is alright:


i have a drop down menu with items to select being the names of eiles available in a directory. after hard search i implemented this code by adding some code lines to the templated constructor of JFrame: note that am working using netbeans 5.5:

public class NewJFrame extends javax.swing.JFrame {

/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
String curDir = System.getProperty("user.dir");
jTextArea1.setText(curDir);
File dir = new File(curDir);

String[] children = dir.list();
if (children == null) {
// Either dir does not exist or is not a directory
}
else {
for (int i=0; i<children.length; i++) {
// Get filename of file or directory
String filename = children[i];
if (filename.indexOf(".txt")!=-1)
jComboBox1.addItem(filename);
}
}
}


i am running the program and until now no errors appear however i think entering a directory can be done in a more efficient way especially if a large number of files exist. who may help me thinking about an alternative solution?

thanks
Sign In or Register to comment.