-
August 20th, 2013, 08:27 PM
#1
text area
I'm trying to create a program where i have an array that holds my image names on a split pane and on the other side of the pane it shows a picture of the selected name.This part of the program works fine but i also have a text area on the frame and what i want it to do is display the text file that pairs with the name selected in the split pane(just like the image). When i run the program the image shows but cmd displays an error message of " java.io.FileNotFoundException: \example.txt <The system cannot find the file specified> The picture of example will show where its supposed to but not the text here is part of my code that deals with this...
Code:
public void valueChanged(ListSelectionEvent e)
{
JList list = (JList)e.getSource();
updateLabel(imageNames[list.getSelectedIndex()]);
}
protected void updateLabel (String name)
{
ImageIcon icon = createImageIcon("/" + name + ".gif");
picture.setIcon(icon);
if (icon != null)
{
picture.setText(null);
} else {
picture.setText("Image not found");
}
try
{
FileReader reader = new FileReader("/" + name + ".txt");
BufferedReader br = new BufferedReader(reader);
fullDes.read( br, null );
br.close();
fullDes.requestFocus();
}
catch(Exception e2) {System.out.println(e2); }
}
protected static ImageIcon createImageIcon(String path)
{
java.net.URL imgURL = GuideScreen.class.getResource(path);
if (imgURL != null)
{
return new ImageIcon(imgURL);
} else {
System.err.println("Could't find file: " + path);
return null;
}
}
(PS fullDes is my textArea).
-
August 20th, 2013, 08:53 PM
#2
-
August 24th, 2013, 04:04 AM
#3
Re: text area
problem fix i simply removed the slash "/" and just kept the quotes empty.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|