Quantcast

Jump to content

» «
Photo

Java eclipse - TextArea

3 replies to this topic
Chris Fromage
  • Chris Fromage

    Homie

  • Members
  • Joined: 22 Sep 2012
  • Japan

#1

Posted 03 April 2013 - 02:27 PM

All right, so I have a project and I am stuck at this point. ( cryani.gif )
This is how it looks like:
user posted image

You chose a car in the ComboBox, and the program gives information about it.
Sounds easy, but when I chose one, I get this:
user posted image

As you see, the text just keeps going.
I want it to go to the next line when it reaches the end of the textArea.

My codes:
TextArea:

private JTextArea infoAuto = new JTextArea();
tijdAuto.setBounds(110, 40, 100, 20);


ComboHandler:

public class ComboHandler implements ActionListener {
public void actionPerformed(ActionEvent arg0) {

if (teken == false) {
keuze = combo.getSelectedItem();
if (keuze == "Audi R8") {
// Audi.teken(g);
BufferedReader in1;
String regel1;
try {
in1 = new BufferedReader(new FileReader(("src\\JavaTextFiles\\Audi.txt"));
while ((regel1 = in1.readLine()) != null) {
infoAuto.setText(regel1);
System.out.println(keuze);
}
in1.close();
repaint();

} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("can not find file");

} catch (IOException e) {
e.printStackTrace();
System.out.println("error while reading file");
}

}

...


and this is the txt-file the system has to read:

De Audi R8 is een sportwagen van het Duitse automerk Audi. Het is gebaseerd op de R8 Racecar en in 2007 kwam de wagen voor het eerst op de markt.


(As you see, I didn't add any new lines because the program then only reads the last line...) sarcasm.gif

Wolf68k
  • Wolf68k

    always howling

  • Members
  • Joined: 12 Mar 2003
  • None
  • Most Knowledgeable [Technology] 2013
    Best Contributor [Technology] 2012

#2

Posted 03 April 2013 - 04:21 PM

This is about programming and would be best here.

*moved*

Jevon
  • Jevon

    Advocate

  • Inactive Staff
  • Joined: 21 Nov 2001
  • None

#3

Posted 03 April 2013 - 08:48 PM

You need to add a call to setLineWrap(true) somewhere, going by http://www.java2s.co...raptextarea.htm (haven't programmed in Java for years so going via Google).

Doesn't look like it's 'intelligent' wrapping though - i.e. wraps by width without taking into account whitespace characters to wrap on word ends.

Chris Fromage
  • Chris Fromage

    Homie

  • Members
  • Joined: 22 Sep 2012
  • Japan

#4

Posted 04 April 2013 - 03:39 PM

Thank you so much Jevon! colgate.gif Have a cookie wink.gif cookie.gif




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users