Hello,
I am very new to java, I have written some codes that has displayed a jList and jButton on a GUI. I have some text files (like assignment.txt etc) that I have saved in the same package with my source code. If I click a button, I want the .txt file to be read and displayed on the jList.
I used buffered reader with AWT and it worked well for me. I simply used
titlesList. add(c);
where c is a String as shown below
private void assignmentButtonActionPerformed(java.awt.event.Act ionEvent evt) {
try
{
BufferedReader cla = new BufferedReader(new FileReader(assignment));
String c;
//read each line from a file
while ((c = ass.readLine()) != null) {
// THIS IS THE ADD C I USED
titlesList.add(c);
}
cla.close();
} catch (IOException e) {
e.printStackTrace();
}
}
It is like Swing does not support add() method, PLEASE I NEED A CODE THAT WILL REPLACE titlesList.add(c); IN sWING SUCH THAT WHEN I CLICK ASSIGNMENT BUTTON, THE .txt THAT HAS ASSIGNMENT QUESTIONS WILL BE DISPLAYED ON A jList.
THANK YOU.