Forums Register Login

Put array of Strings into JList

+Pie Number of slices to send: Send
i found out the problem in my program. here is my program pls check for me:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Scanner;

public class GlossarySearch extends JFrame
{ private JTextField term;
private JList select;
private JTextField definition;
private JButton next;
private JButton previous;
public String[] title=new String[10];
public String[] explain=new String[20];
//private Search search;

public GlossarySearch(String title){
//search=new Search();

buildGUI();
setTitle(title);
pack();
setVisible(true);
}

private void buildGUI(){
String sModel=null;
Container contentPane=getContentPane();
contentPane.setLayout(new BorderLayout());
term=new JTextField(10);
definition=new JTextField(100);
next=new JButton("Next Term");
previous=new JButton("Previous Term");
select=new JList(sModel);
for(int i=0;i<10;i++){
sModel.addElement(title[i]);
}
contentPane.add("North",select);
JPanel inputPanel=new JPanel();
inputPanel.add(term);
inputPanel.add(definition);
contentPane.add("Center",inputPanel);
JPanel inputPanel2=new JPanel();
inputPanel2.add(next);
inputPanel2.add(previous);
contentPane.add("South",inputPanel2);

}
public void readText(){
String myFileName = "test.txt";
int a=0;
int b=0;
try{

File myFile = new File(myFileName);
Scanner scanMyFile = new Scanner(myFile);
scanMyFile.useDelimiter("\r\n");
if (scanMyFile.hasNext()) {
title[a]= scanMyFile.next();
a=a+1;

if (scanMyFile.hasNext()) {
explain[b]= scanMyFile.next();
b=b+1;

}
}

} catch(Exception ex) {

System.out.println("exception "+ex.getMessage()+" caught");

}

//System.out.println("file "+myFileName+ " contains "+wordCount+ " words.");

}


public static void main(String args[]){
new GlossarySearch("Glossary Search");
}
}

i want to put what i read from text file into the list but i fail to do that. pls tell me wat the problem is this.thank you

regars,
albert
[ August 12, 2006: Message edited by: Ernest Friedman-Hill ]
+Pie Number of slices to send: Send
You'd get a lot more answers to questions like this if you simply asked "How do I put an array of Strings into a JList?" in the Swing forum, instead of expecting people to slog through a hundred lines of unformatted spaghetti in Java in General (Intermediate) to discover that this is what you're asking.

I'm going to change the subject of this message to "Put array of Strings into JList", and move it to the Swing forum. Perhaps then someone will answer your question.
+Pie Number of slices to send: Send
> i want to put what i read from text file into the list but i fail to do that.

try this
(I've simplified your code to dealing with only the above)

Space pants. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1480 times.
Similar Threads
JTabbedPane
Tab Problem!! PLZ HELP
First time using an applet in a website
GUI control
Dialog Input Question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:36:00.