I'm new to JTextArea and JScrollPane, whenever I compile I get this error, Project3.java:95: cannot find symbol symbol : class Dimension location: class Project3 scroll.setPreferredSize(new Dimension(200, 400));
Can someone please help me?
JTextArea listBox = new JTextArea(input);
JScrollPane scroll = new JScrollPane(listBox);
listBox.setLineWrap(true);
listBox.setWrapStyleWord(true);
scroll.setPreferredSize(new Dimension(200, 400));
JOptionPane.showMessageDialog(null, scroll, "Dictionary enteries" JOptionPane.PLAIN_MESSAGE);
return aLineFromFile;
This is the full method.
public static String listDictionary()throws IOException
{
String input = "";
BufferedReader br = new BufferedReader(new FileReader("dictionary.txt"));
String aLineFromFile = null;
while((aLineFromFile = br.readLine()) != null)
{
input += aLineFromFile + "\n";
}
br.close();
JTextArea listBox = new JTextArea(input);
JScrollPane scroll = new JScrollPane(listBox);
listBox.setLineWrap(true);
listBox.setWrapStyleWord(true);
scroll.setPreferredSize(new Dimension(200, 400));
JOptionPane.showMessageDialog(null, scroll, "Dictionary enteries", JOptionPane.PLAIN_MESSAGE);
return aLineFromFile;
}
I have imported, import java.io.; import javax.swing.; import java.util.*;
Dimension is in java.awt, so add import java.awt.Dimension;
I would suggest using Eclipse or Netbeans. They will tell you that you need to add imports like this.