permaculture playing cards*
The moose likes Swing / AWT / SWT and the fly likes Blank JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Blank JFrame" Watch "Blank JFrame" New topic
Author

Blank JFrame

Nigel Crowhurst
Greenhorn

Joined: Nov 11, 2005
Posts: 6
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

Joined: Aug 31, 2004
Posts: 11343

Hi Nigel,

I'm moving this to the Swing forum, where the GUI experts hang out...


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
sounds like you have setVisible(true) (or show()), prior to the lines
where you add the components to the 2nd frame
Nigel Crowhurst
Greenhorn

Joined: Nov 11, 2005
Posts: 6
- 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

Joined: Nov 11, 2005
Posts: 6
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Blank JFrame