File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Blank JFrame

 
Nigel Crowhurst
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings, within a JFrame I have a few JButtons, a few JLabels, and a JTextField. One of the JButtons opens a new window (JFrame). An anonymous actionPerformed inner class calls another JFrame object within the existing object. The inner JFrame object opens a new window like it should. However the window is blank. The two JLabels, two JButtons, and two JLists are not visible until... this is the tricky part, I click on any of the four edges of the window frame. Then the components are in view and the whole thing works properly. The program compiles and the setLayout, setSize, setVisible, etc. are identical to outer JFrame that opens fine when the program is started. I've tried everything I can think of, and was hoping someone else has seen this phenomenon before. Many thanks.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nigel,

I'm moving this to the Swing forum, where the GUI experts hang out...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds like you have setVisible(true) (or show()), prior to the lines
where you add the components to the 2nd frame
 
Nigel Crowhurst
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- Hello Marc,
Thank you so much for moving this to the Swing forum. I have a lot to learn about JavaRanch.com, and way way more about Java itself. I'm anxious to do this so I can be in a spot to where I can help others. This really helped me out, and I really appreciate it.

Very kindly,
Nigel
 
Nigel Crowhurst
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael!
You were right! Mercy. The instructor for my Java class at school said to just take that class out and KISS my program assignment, and didn't know how to fix it. And here you fixed it with one sentence. I moved setVisible(true); to the bottom of the inner class and it works great! What threw me was that the instructor has us students putting "main" in a different class in a separate file. So all "main" does is declare a new object of that class, setDefaultCloseOperation(), setSize(), and setVisible(true). So it looked to me like setVisible() could go right after the class was declared, so I did the same thing for the inner class. Now I know better. So in main, the object is declared, it goes out and sets up all the JButtons, JLabels, etc. in the other file, and comes back to main to setSize, setVisible, etc. I hope that's right. Thanks for saving my project.

Very kindly,
Nigel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic