.setVisible(true); // I can't see what I am missing

57 views
Skip to first unread message

RRRaney

unread,
Jun 27, 2011, 8:55:55 PM6/27/11
to google-we...@googlegroups.com
Hello,
 
I would like to figure out how to build my entire container before I show it.
I have this example to help explain and work with.
This builds the container as I would like (if I remove the visibility:hidden).
With the example as is it never shows the ButtonContainer, just sits there as blank page.
I can't see what it is that I am missing.
 
My.html
-------
<body>
    <div class = "Container"
         id    = "ButtonContainer">
        <div id = "Buttons">
        </div>
    </div>
</body>

My.css
------
.Container
{
    outline:#C0C0C0 inset thin;
}
#ButtonContainer
{
    visibility: hidden;
}

My.java
-------
public class SmartPage implements EntryPoint
{
    public void onModuleLoad()
    {
        HLayout Buttons = new HLayout();
        Buttons.setMembersMargin(15);
        IButton ButtonOne = new IButton("Button One");
        IButton ButtonTwo = new IButton("Button Two");
        Buttons.addMember(ButtonTwo);
        Buttons.addMember(ButtonOne);
        VLayout ButtonLayout = new VLayout();
        ButtonLayout.addMember(Buttons);
        ButtonLayout.setHeight(ButtonOne.getHeight());
        RootPanel.get("Buttons").add(ButtonLayout);
        ButtonLayout.draw();
        RootPanel.get("ButtonContainer").setVisible(true);
    }
}
Thanks,
 
Raney 

Alisson Prestes

unread,
Jun 27, 2011, 9:00:50 PM6/27/11
to google-we...@googlegroups.com
The CSS attribute that you must declare is "display" instead of visibility. This is the attribute that the setVisible method affects.

#ButtonContainer
{
    display: none;
}
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/TA2_kmOKOFUJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

David Chandler

unread,
Jun 27, 2011, 10:00:47 PM6/27/11
to google-we...@googlegroups.com
The implementation of RootPanel.setVisible() uses the style attribute "display," which is orthogonal to visibility:hidden.

  public static native void setVisible(Element elem, boolean visible) /*-{

    elem.style.display = visible ? '' : 'none';

  }-*/;


Best form is to control visibility using styles directly OR by calling setVisible(), but don't mix the two.

/dmc

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/TA2_kmOKOFUJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
David Chandler
Developer Programs Engineer, Google Web Toolkit
w: http://code.google.com/
b: http://googlewebtoolkit.blogspot.com/
t: @googledevtools

t.dave

unread,
Jun 28, 2011, 12:47:16 AM6/28/11
to Google Web Toolkit
".setVisible(true); // I can't see what I am missing" - enjoyed the
pun. :)

Message has been deleted

RRRaney

unread,
Jun 28, 2011, 8:34:06 AM6/28/11
to google-we...@googlegroups.com

Alisson,

I made the following change, but still does not display.

My.css
------
#ButtonContainer
{
    Old:visibility: hidden;
    New:display: none;
}

My.Java
-------
    RootPanel.get("ButtonContainer").setVisible(true);

Raney

RRRaney

unread,
Jun 28, 2011, 8:38:30 AM6/28/11
to google-we...@googlegroups.com

David,

I have tried to do something like you have suggested but I just
can't see any properties or functions of Element that look like what you
have shown.

My.css
------
#ButtonContainer
{
    Old:visibility: hidden;
    New:display: none;
}

My.java
-------
import com.google.gwt.dom.client.Element;


public class SmartPage implements EntryPoint
{
    public void onModuleLoad()
    {
        HLayout Buttons = new HLayout();
        Buttons.setMembersMargin(15);
        IButton ButtonOne = new IButton("Button One");
        IButton ButtonTwo = new IButton("Button Two");
        Buttons.addMember(ButtonTwo);
        Buttons.addMember(ButtonOne);
        VLayout ButtonLayout = new VLayout();
        ButtonLayout.addMember(Buttons);
        ButtonLayout.setHeight(ButtonOne.getHeight());
        RootPanel.get("Buttons").add(ButtonLayout);
        ButtonLayout.draw();

        Element E = RootPanel.get("ButtonContainer").getElement();
        E.  (I can't see anything that looks like it will do the trick).
    }
}

Raney

RRRaney

unread,
Jun 28, 2011, 8:40:55 AM6/28/11
to google-we...@googlegroups.com
Thanks, but I think that you missed my . (punt).
 
Raney
 
 

Thomas Broyer

unread,
Jun 28, 2011, 8:50:59 AM6/28/11
to google-we...@googlegroups.com


On Tuesday, June 28, 2011 1:39:53 PM UTC+2, RRRaney wrote:
 
Alisson,
 
I made the following change, but still does not display.

My.css


------
#ButtonContainer
{
    Old:visibility: hidden;
    New:display: none;
}

-----------------------------------------------------------
David,
 
I have tried to do something like you have suggested but I just
can't see any properties or functions of Element that look like what you
have shown.

David didn't suggest anything (in terms of code at least), he copy/pasted the code for UIObject.setVisible(Element,boolean), which is called by UIObject.setVisible(boolean).

As you'll see, when calling setVisible(true), you'll actually reset 'display' to its default value, which in your case would be the one set by your stylesheet with the #ButtonContainer class. That's why David said to either always use CSS, or always use setVisible.

It would be different if you set the display style locally, inline: <div id=ButtonContainer style="display: none">, where resetting to the default value would really dismiss the previous 'non' value, rather than "remove a local override".
Alternatively, you could *add* a "local override" using Document.get().getElementById("ButtonContainer").getStyle().setDisplay(Display.BLOCK) (no need for RootPanel if it's not to add child widgets).

It all boils done to knowing what you're doing, and knowing the tools you're using (and GWT is open-source, so it's more than easy to know what it does!)

RRRaney

unread,
Jun 28, 2011, 11:32:01 AM6/28/11
to google-we...@googlegroups.com
Thanks to all,
 
This does what I was looking for.
 
Raney
 
 
My.html
-------
<body>
    <div class = "Container"
         id    = "ButtonContainer">
        <div id = "Buttons">
        </div>
    </div>
</body>
My.css
------
Nothing about display or visibility for #ButtonContainer
 
 
My.java
-------
public class SmartPage implements EntryPoint
{
    public void onModuleLoad()
    {
-->   RootPanel.get("ButtonContainer").setVisible(false);
 
        HLayout Buttons = new HLayout();
        Buttons.setMembersMargin(15);
        IButton ButtonOne = new IButton("Button One");
        IButton ButtonTwo = new IButton("Button Two");
        Buttons.addMember(ButtonTwo);
        Buttons.addMember(ButtonOne);
        VLayout ButtonLayout = new VLayout();
        ButtonLayout.addMember(Buttons);
        ButtonLayout.setHeight(ButtonOne.getHeight());
        RootPanel.get("Buttons").add(ButtonLayout);
        ButtonLayout.draw();
 
-->    RootPanel.get("ButtonContainer").setVisible(true);
    }
}
 
This does what I was looking for.
 
 
Reply all
Reply to author
Forward
0 new messages