The Artima Developer Community
Sponsored Link

Java Answers Forum
I have a problem with setVisible(true) !!!!!!

2 replies on 1 page. Most recent reply: Jan 5, 2003 5:11 PM by Thomas SMETS

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Reza

Posts: 1
Nickname: leon
Registered: Jan, 2003

I have a problem with setVisible(true) !!!!!! Posted: Jan 1, 2003 7:55 AM
Reply to this message Reply
Advertisement
Hi!

Could you tell me please, how can I use the method
getSize() before I call the method setVisible(true)??

If I call the method getSize() before setVisible(true)
then return getSize() only 0 !!!!!
I must call getSize() before setVisible(true).

I tried to call the methods addNotify() and validate()
before I call the getSize() but without success!!

Thank you for your help ;-))

Code:

import java.awt.*;

class Test extends Frame
{
Test()
{
setSize(200, 100);
setLayout(new FlowLayout());
Button b=new Button("test");
add(b);
System.out.println("Size: "+ b.getSize()); //It doesn't work!!!!
setVisible(true);
}
public static void main(String args[])
{
(new Test());
}
}


robbies

Posts: 2
Nickname: robbies
Registered: Jan, 2003

Re: I have a problem with setVisible(true) !!!!!! Posted: Jan 5, 2003 9:43 AM
Reply to this message Reply
class Test extends Frame
{
Test()
{
setSize(200, 100);
setLayout(new FlowLayout());
Button b=new Button("test");
add(b);
System.out.println("Size: "+ b.getSize()); //It doesn't work!!!!
//setVisible(true); It should not be used here!!!
}
public static void main(String args[])
{
Test t=new Test());
t.setVisible(true);//it should be used here


}
}

-----
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar

http://www.pivotonic.com
-----------------------------

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: I have a problem with setVisible(true) !!!!!! Posted: Jan 5, 2003 5:11 PM
Reply to this message Reply
Robbies,

You gave a working solution but you didn't explained the WHY :-))

The most likely reason the setvisible (true); or getSize (); returns 0 (zero) is that the Object (of type Frame ) is not completely built in memory, yet. The various internal state might be initialized afterwards.

It's too late for me for now, but I think it's worth trying with a JFrame

Rgds,

Thomas,

Flat View: This topic has 2 replies on 1 page
Topic: Google Api: A lame question Previous Topic   Next Topic Topic: how can i run a programme on different computers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use