Display a text file into a jTextArea base on the option selected in the jComboBox

Viewed 8

I want to display a text file in a jtextarea based on the option selected int he jcombobox. This is my code but it does not seem to work properly

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        if(jComboBox1.getSelectedItem() == "Enchanted")
        {
             try {
                String textLine;
                FileReader fr = new FileReader("enchanted.txt");
                BufferedReader reader = new BufferedReader(fr);

                while((textLine=reader.readLine()) != null){

                    jTextArea2.read(reader, "jTextArea2");
                }
            }
                    catch (IOException ioe) {
                System.err.println(ioe);
                System.exit(1);
            }
            }
    
    }       
0 Answers
Related