• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

setLineWrap(true); crashes my App

I have two JTextArea's in my app. I set them to .setLineWrap(true); When ever i do this, the app would randomly crash, i.e not continue the rest of the code after the setLineWrap() method (i know this because i put print statements after the setLineWrap and this print statement doesn't get printed). soemtimes  the app will work (it is completely random). When ever i remove the setLineWrap(true); the app will always work.

HEEEEEEEEEELP!!! this is really stupid, why is this this crashing my app?
0
don_milz
Asked:
don_milz
  • 6
  • 6
  • 4
1 Solution
 
objectsCommented:
ake sure you are calling it from the event dispatch thread

0
 
objectsCommented:
EventQueue.invodeLater(new Runnable() {
   public void run() {
      ta.setLineWrap(true);
   }
});

0
 
objectsCommented:
typo

EventQueue.invokeLater(new Runnable() {
   public void run() {
      ta.setLineWrap(true);
   }
});

0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
CEHJCommented:
Please post your code
0
 
don_milzAuthor Commented:
Yes i am running it from the event dispatch thread.  the second piece of code is inside the chat constructor. The component variables are defined as instance variables in the chat class.
java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new chat();
				showControls();
			}
});
 
....
....
// what follows is inside the Chat constructor
....
....
frame = new JFrame("My APP");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1010, 650); 
frame.setLocationRelativeTo(null); 
frame.setResizable(false); 
frame.setEnabled(false);
 
mainPanel = new JPanel(null);
 
chatArea = new JTextArea();
chatArea.setEditable(false);
chatArea.setFont(new Font("Serif", Font.BOLD, 14)); 
chatArea.setLineWrap(true);
chatArea.setWrapStyleWord(true); 
 
JScrollPane scrlPane = new JScrollPane(chatArea);
 
typeArea = new JTextArea();
typeArea.setEditable(true);
typeArea.setFont(new Font("Serif", Font.BOLD, 14)); 
typeArea.setLineWrap(true);
typeArea.setWrapStyleWord(true);
 
JScrollPane scrlPane2 = new JScrollPane(typeArea);
 
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrlPane, scrlPane2);
splitPane.setBounds(10,10,330,560);
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(480);
 
mainPanel.add(splitPane);
mainPanel.add(send);
		
frame.getContentPane().add(mainPanel,BorderLayout.CENTER);
		
frame.setVisible(true);

Open in new window

0
 
don_milzAuthor Commented:
Sorry...line 18 (frame.setEnabled(false);) shouldn't be there.
0
 
objectsCommented:
are there no other threads involved?
How exactly is it crashing?

0
 
don_milzAuthor Commented:
The problem occurs in line 25 and line 33, sometimes it would randomly stop just before line 25, sometimes it would randomly stop just before line 33, and sometimes it would work perfectly.

But when it does stop...it will only stop just before those 2 lines....I know this because i put print statements before and after every line.
0
 
CEHJCommented:
Is that the end of the constructor or is anything else happening in it?
0
 
objectsCommented:
do a thread dump next time it stops, that'll tell u what it is doing

0
 
don_milzAuthor Commented:
Yes there are other threads....

sorry i was mistaken...the above code isn't in my chat constructor but rather in one of it's public methods. here is my structure.

the chat constructor calls another class's constructor and passes itself as a parameter.....that other class in turn does something stuff....part of which has a SwingWorker which refers to the Chat object class that was passed in and calls it's method that contains the above code.

0
 
don_milzAuthor Commented:
how do i do a thread dump?
0
 
CEHJCommented:
You could easily be sitting on the event thread, despite your efforts to do so. Ctrl-Break gives you a thread dump in Windows
0
 
CEHJCommented:
>>despite your efforts to do so = despite your efforts not to do so
0
 
objectsCommented:
> the chat constructor calls another class's constructor and passes itself as a parameter.....that other class in turn does something stuff....part of which has a SwingWorker which refers to the Chat object class that was passed in and calls it's method that contains the above code.

I'd suggest doing that call *after* the Chat has been created

0
 
don_milzAuthor Commented:
Yes I have taken your suggestion to call that stuff after the chat's gui components have been created.

So far after dozens of runs there are no crashes, so i would assume this has solved the problem. But It could just be a coincidence that all those test runs have worked fine. because remember, before it was randomly working....on off kind of thing. I had a feeling it had something to do with the multiple threads i'm running, because there are no other explanations for random behaviour.

So yeah, so far so good....I'll run a several more tests to convince myself that it is working fine now before closing this question.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now