wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes why doesn't this code work? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why doesn Watch "why doesn New topic
Author

why doesn't this code work?

Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
I posted this in the swing forum but havent seen a reply. This code should display a box with six labels on the left, six text fields on the right, and two buttons at the bottom, but all that appears is the box with its title, "Calculation of Property Taxes." Will you compile and run it and see if it works, meaning the problem is something on my own computer that keeps it from working right. Note that it isnt supposed to handle any data or perform calculations yet, only display the correct box.



[ February 03, 2006: Message edited by: Jesse Crockett ]
Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129


I think this is the problem. I can't find this method in the documentation. Also, I may have initialized it wrong. Should this line work?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Please don't post the same question in multiple forums; if you check your other copy, you'll see that someone asked you for more info which would have led to the solution.

Anyway, the problem is that you've called setVisible first, and then built your GUI. Because of this, the frame will defer actually laying out your components until validate() is called (Swing defer doing the layout for any component that's actually visible on the screen.) That may cause an unpleasant "flashing" effect; therefore it's better to do the setVisible call last instead.


[Jess in Action][AskingGoodQuestions]
Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
Sorry about the double post. I had not received an email message for the other reply at the time I started this thread.

What is validate()? is that something that JFrame does automatically?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

No. You call it.
Mark Newton
Ranch Hand

Joined: Jan 31, 2006
Posts: 129
Originally posted by Jesse Crockett:
What is validate()? is that something that JFrame does automatically?


Basically, the validate() method 'refreshes' the container that you're calling it on, if you call validate() on your JFrame, it will be re-drawn, as will everything in it.

As Ernest said though, because it doesn't matter in your example when you display the JFrame (by using setVisible(true)), you'd be better off setting up the JFrame and all of it's contents, and only calling setVisible(true) at the end, that way it all gets set up before you display it.
Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
I wouldn't have double posted if JavaRanch had sent an email reply notification. I had been receiving those for a while, but now they have suddenly stopped coming. How do I select 'email reply notification' again? I don't find it under 'view/update profile'.

About the setVisible() method, I changed it to the last method call in the constructor and my program works perfectly. Thanks!

About the validate() method. If I understand what you say, then for instance I could set up a while loop that changes the layout, which would require use of the validate() method, right?

This is all very interesting.
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

I have checked your application do one thing after running the application just resize it once and click on the application panel it will show you everything you have drawn on panel. It's not a problem. just check it out.


The Best way to predict your future is to create it - Every great individual common man
Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
Here is the final program:



[ February 06, 2006: Message edited by: Jesse Crockett ]
[ February 06, 2006: Message edited by: Jesse Crockett ]
 
wood burning stoves
 
subject: why doesn't this code work?