Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

setLineWrap(true); crashes my App

Posted on 2009-02-09
16
Medium Priority
?
389 Views
Last Modified: 2012-05-06
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
Comment
Question by:don_milz
  • 6
  • 6
  • 4
16 Comments
 
LVL 92

Expert Comment

by:objects
ID: 23594479
ake sure you are calling it from the event dispatch thread

0
 
LVL 92

Expert Comment

by:objects
ID: 23594488
EventQueue.invodeLater(new Runnable() {
   public void run() {
      ta.setLineWrap(true);
   }
});

0
 
LVL 92

Expert Comment

by:objects
ID: 23594493
typo

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

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:CEHJ
ID: 23594497
Please post your code
0
 

Author Comment

by:don_milz
ID: 23594879
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
 

Author Comment

by:don_milz
ID: 23594895
Sorry...line 18 (frame.setEnabled(false);) shouldn't be there.
0
 
LVL 92

Expert Comment

by:objects
ID: 23594917
are there no other threads involved?
How exactly is it crashing?

0
 

Author Comment

by:don_milz
ID: 23594919
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 23594931
Is that the end of the constructor or is anything else happening in it?
0
 
LVL 92

Expert Comment

by:objects
ID: 23594946
do a thread dump next time it stops, that'll tell u what it is doing

0
 

Author Comment

by:don_milz
ID: 23594966
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
 

Author Comment

by:don_milz
ID: 23594971
how do i do a thread dump?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 23595056
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 23595065
>>despite your efforts to do so = despite your efforts not to do so
0
 
LVL 92

Accepted Solution

by:
objects earned 375 total points
ID: 23595074
> 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
 

Author Comment

by:don_milz
ID: 23595242
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question