Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why is JTextArea not visible?  RSS feed

 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a class (StatusDialog) that extends JDialog. It is very simple, composed of a JFrame containing a JTextArea. It takes as parameters a BufferedInputStream and an OutputStream. Text from the BufferedInputStream is appended to the JTextArea. If the user presses "enter", this is written to the OutputStream.
It worked so well with a test program! But when I took StatusDialog and used it with another (production) class, a problem arose. Now when the dialog comes up, the JTextArea isn't visible. I didn't change any of the code or what is being passed to it. There's a slight difference in environment, as StatusDialog is now part of a package.
Does anyone know what might be causing this? The code for StatusDialog follows.
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I copied the code you supplied to a separate class file, and put this in a main method of a test class:

The dialog and JTextArea showed up just fine (jre 1.3.1, WinNT).
What Java version and OS are you using?
You may want to (in general) try using a more advanced layout manager for your main panel. BorderLayout seems to be appropriate here.
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using Java 1.4.0 on a Solaris 8 system.
I've tried using BorderLayout, and that didn't work, either.
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does show up? A dialog with no GUI components in it? What size is it, the size you'd expect or very small? Is nothing appearing at all? Are you getting any exceptions thrown?
Bill
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An empty dialog shows up, properly sized, but without the JTextArea. No exceptions are thrown.
Originally posted by Bill Liteplo:
What does show up? A dialog with no GUI components in it? What size is it, the size you'd expect or very small? Is nothing appearing at all? Are you getting any exceptions thrown?
Bill
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe the background of the JTextArea is the same as the surrounding panel/frame. Try playing with colors, or better yet, add some other components to the dialog and see if they show up.
If the dialog was the proper size, my intuition says that the JTextArea was actually added to it. Otherwise (unless you have set the dialog size manually), it would not be so big.
Bill
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I was thinking. I already messed around with the colors, but nothing came of it. After messing around for a while, I think the problem has something to do with the class' location in the package hierarchy.
Originally posted by Bill Liteplo:
Maybe the background of the JTextArea is the same as the surrounding panel/frame. Try playing with colors, or better yet, add some other components to the dialog and see if they show up.
If the dialog was the proper size, my intuition says that the JTextArea was actually added to it. Otherwise (unless you have set the dialog size manually), it would not be so big.
Bill
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, here's the situation. This is the way the dialog is created:
Main program (GUI) -->
Config Dialog (no GUI in this case)-->
(instance of) Tar Compressor (no GUI) -->
Status Dialog (has GUI)
If I have the Status Dialog created by any class except the main program, I get the problem I've been describing. If the main program calls the dialog, it works. Any ideas how to solve this one?
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure there are no package conflicts or classpath issues? You don't have an old version of StatusDialog.class lingering around somewhere accessible by your production code?
Bill
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Figured it out!
The problem is caused by the fact that the call to create the dialog is triggered by a button and is contained in an actionListener. I'm not sure how to work around this little quirk. Having the actionListener call a method that does the dialog creation does not help.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that the method call :


is blocking on input... According to the JavaDocs :

This method blocks until input data is available, end of file is detected, or an exception is thrown.


Enclose the code in the do...while loop with a test:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!