You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Brendan cheng <cc...@hotmail.com> on 2011/09/17 10:57:01 UTC

How to dynamically add component to window

Hi,
I must say I'm totally new to Pivot.  I'm trying add a box pane to my window's scroll pane but even the code compiled properly, the box pane just doesn't show up.
Here is the snippet from my main program.
	@Override
    	public void startup(Display display, Map<String, String> properties) throws Exception {
        String language = properties.get(LANGUAGE_KEY);
        Locale locale = (language == null) ? Locale.getDefault() : new Locale(language);
        Resources resources = new Resources(ClientWindow.class.getName(), locale);


        BXMLSerializer bxmlSerializer = new BXMLSerializer();
        window = (ClientWindow)bxmlSerializer.readObject(getClass().getResource("client_window.bxml"),
            resources);
        ScrollPane rightScrollPane = (ScrollPane) bxmlSerializer.getNamespace().get("rightScrollPane");
        BoxPane commentPane = null;
        try {
			commentPane = (CommentPane)bxmlSerializer.readObject(getClass().getResource("thumbnail/comment_pane.bxml"),
			    resources);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (SerializationException e) {
			e.printStackTrace();
		}
        rightScrollPane.add(commentPane);
        window.open(display);(display);
What do you recommend to do this job in pivot?
Thanks in advance!
Brendan 		 	   		  

RE: How to dynamically add component to window

Posted by Brendan cheng <cc...@hotmail.com>.
Can you show me an example?How do you modify you Web Queries example to achieve?I'm not clear where to the serializer.  Do you use bxml:include like this:<itemRenderer><bxml:inlcude src = "ResultItemRenderer.bxml"/></itemRenderer> 
Thanks...From: gk_brown@verizon.net
Subject: Re: How to dynamically add component to window
Date: Sat, 17 Sep 2011 11:37:45 -0400
To: user@pivot.apache.org



Yes, you can easily create a list item renderer whose structure is defined in BXML by using a root element that implements the ListView.ItemRenderer interface. For example, you could create a subclass of TableView called CommentItemRenderer that implements this interface. You could use @BXML annotations to get access to the dateLabel, authorLabel, and summaryLabel elements so you can set their values in the render() method.
On Sep 17, 2011, at 9:07 AM, Brendan cheng wrote:This example show the format of ListView is created inside java code, so that to change the style of the list may have to change the code.But I want to make use of BXML file for the ListView, is that possible to achieve in Pivot? 

From: gk_brown@verizon.net
Subject: Re: How to dynamically add component to window
Date: Sat, 17 Sep 2011 08:10:38 -0400
To: user@pivot.apache.org

Sounds like this might be a good use case for a custom list view item renderer. Here is an example:
http://pivot.apache.org/tutorials/web-queries.html
On Sep 17, 2011, at 7:58 AM, Brendan cheng wrote:My program need to show a series of comment displayed in a sroll pane somewhere in my main window.I created a bxml file called CommentPane which take three variables Date, Author and comment.And the list of comments stored in database.
so my CommentPane code like this:<thumbnail:CommentPane    xmlns:bxml="http://pivot.apache.org/bxml"    xmlns:thumbnail="hk.itags.gui.thumbnail"    xmlns="org.apache.pivot.wtk">    <BoxPane>    <TablePane>        <columns>            <TablePane.Column width="1*"/>        </columns>         <TablePane.Row height="-1">            <Border styles="{color:'#999999'}">            	<TablePane>            		<columns>            			<TablePane.Column width="-1"/>            			<TablePane.Column width="1*"/>            			<TablePane.Column width="-1"/>         ;			</columns>        			<TablePane.Row height="-1">        				<Label bxml:id="dateLabel" />        				<Label bxml:id="authorLabel" />        				<PushButton buttonData=">" styles="{minimumAspectRatio:1.5}"/>         			</TablePane.Row>        		</TablePane>            </Border>		</TablePane.Row>				<TablePane.Row height="1*">            <Border styles="{color:'#999999'}">            	<BoxPane styles="{padding:6, verticalAlignme
 nt:'top'}">        			<Label bxml:id="summaryLabel" text="Summary"/>        			<TextArea bxml:id="descriptionTextArea" minimumHeight="2"/>    			</BoxPane>            </Border>		</TablePane.Row>    </TablePane>    </BoxPane></thumbnail:CommentPane>
if I use BXML serializer, i can load one into my scroll pane with setView.  but when I load a second one, I have an error message "ID dateLabel is already in use".
I can't use bxml:include in bxml file because I don't know until I read the database.
Hopefully, that's clear.
Brendan



> Date: Sat, 17 Sep 2011 17:45:04 +0700
> Subject: Re: How to dynamically add component to window
> From: cbartlett.x@gmail.com
> To: user@pivot.apache.org
> 
> Here is a test that shows how to use the 'inline' flag to include BXML.
> http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/include_test.bxml
> http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/include_test.content.bxml
> 
> On 17 September 2011 17:42, Chris Bartlett <cb...@gmail.com> wrote:
> &g t; 2011/9/17 Brendan cheng <cc...@hotmail.com>:
> >> Actually, I was trying to inject a series of box pane from the bxml files.
> > Are you talking about using BXML's 'include' functionality?
> > http://pivot.apache.org/tutorials/bxml-primer.html
> >
> > If you are, then you can include the same BXML frag ments multiple
> > times (or any fragments, including ones where the BXML IDs of
> > Components might clash) by using the inline flag
> > <bxml:include src="foo.bxml" inline="true"/>


 		 	   		  

Re: How to dynamically add component to window

Posted by Greg Brown <gk...@verizon.net>.
Yes, you can easily create a list item renderer whose structure is defined in BXML by using a root element that implements the ListView.ItemRenderer interface. For example, you could create a subclass of TableView called CommentItemRenderer that implements this interface. You could use @BXML annotations to get access to the dateLabel, authorLabel, and summaryLabel elements so you can set their values in the render() method.

On Sep 17, 2011, at 9:07 AM, Brendan cheng wrote:

> This example show the format of ListView is created inside java code, so that to change the style of the list may have to change the code.
> But I want to make use of BXML file for the ListView, is that possible to achieve in Pivot? 
> 
> From: gk_brown@verizon.net
> Subject: Re: How to dynamically add component to window
> Date: Sat, 17 Sep 2011 08:10:38 -0400
> To: user@pivot.apache.org
> 
> Sounds like this might be a good use case for a custom list view item renderer. Here is an example:
> 
> http://pivot.apache.org/tutorials/web-queries.html
> 
> On Sep 17, 2011, at 7:58 AM, Brendan cheng wrote:
> 
> My program need to show a series of comment displayed in a sroll pane somewhere in my main window.
> I created a bxml file called CommentPane which take three variables Date, Author and comment.
> And the list of comments stored in database.
> 
> so my CommentPane code like this:
> <thumbnail:CommentPane
>     xmlns:bxml="http://pivot.apache.org/bxml"
>     xmlns:thumbnail="hk.itags.gui.thumbnail"
>     xmlns="org.apache.pivot.wtk">
>     <BoxPane>
>     <TablePane>
>         <columns>
>             <TablePane.Column width="1*"/>
>         </columns>
>  
>         <TablePane.Row height="-1">
>             <Border styles="{color:'#999999'}">
>             	<TablePane>
>             		<columns>
>             			<TablePane.Column width="-1"/>
>             			<TablePane.Column width="1*"/>
>             			<TablePane.Column width="-1"/>
>          ;			</columns>
>         			<TablePane.Row height="-1">
>         				<Label bxml:id="dateLabel" />
>         				<Label bxml:id="authorLabel" />
>         				<PushButton buttonData=">" styles="{minimumAspectRatio:1.5}"/> 
>         			</TablePane.Row>
>         		</TablePane>
>             </Border>
> 		</TablePane.Row>
> 		
> 		<TablePane.Row height="1*">
>             <Border styles="{color:'#999999'}">
>             	<BoxPane styles="{padding:6, verticalAlignment:'top'}">
>         			<Label bxml:id="summaryLabel" text="Summary"/>
>         			<TextArea bxml:id="descriptionTextArea" minimumHeight="2"/>
>     			</BoxPane>
>             </Border>
> 		</TablePane.Row>
> 
>     </TablePane>
>     </BoxPane>
> </thumbnail:CommentPane>
> 
> if I use BXML serializer, i can load one into my scroll pane with setView.  but when I load a second one, I have an error message "ID dateLabel is already in use".
> 
> I can't use bxml:include in bxml file because I don't know until I read the database.
> 
> Hopefully, that's clear.
> 
> Brendan
> 
> 
> 
> 
> > Date: Sat, 17 Sep 2011 17:45:04 +0700
> > Subject: Re: How to dynamically add component to window
> > From: cbartlett.x@gmail.com
> > To: user@pivot.apache.org
> > 
> > Here is a test that shows how to use the 'inline' flag to include BXML.
> > http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/include_test.bxml
> > http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/include_test.content.bxml
> > 
> > On 17 September 2011 17:42, Chris Bartlett <cb...@gmail.com> wrote:
> > &g t; 2011/9/17 Brendan cheng <cc...@hotmail.com>:
> > >> Actually, I was trying to inject a series of box pane from the bxml files.
> > > Are you talking about using BXML's 'include' functionality?
> > > http://pivot.apache.org/tutorials/bxml-primer.html
> > >
> > > If you are, then you can include the same BXML frag ments multiple
> > > times (or any fragments, including ones where the BXML IDs of
> > > Components might clash) by using the inline flag
> > > <bxml:include src="foo.bxml" inline="true"/>
> 
> 


RE: How to dynamically add component to window

Posted by Brendan cheng <cc...@hotmail.com>.
This example show the format of ListView is created inside java code, so that to change the style of the list may have to change the code.But I want to make use of BXML file for the ListView, is that possible to achieve in Pivot? 

From: gk_brown@verizon.net
Subject: Re: How to dynamically add component to window
Date: Sat, 17 Sep 2011 08:10:38 -0400
To: user@pivot.apache.org



Sounds like this might be a good use case for a custom list view item renderer. Here is an example:
http://pivot.apache.org/tutorials/web-queries.html
On Sep 17, 2011, at 7:58 AM, Brendan cheng wrote:My program need to show a series of comment displayed in a sroll pane somewhere in my main window.I created a bxml file called CommentPane which take three variables Date, Author and comment.And the list of comments stored in database.
so my CommentPane code like this:<thumbnail:CommentPane    xmlns:bxml="http://pivot.apache.org/bxml"    xmlns:thumbnail="hk.itags.gui.thumbnail"    xmlns="org.apache.pivot.wtk">    <BoxPane>    <TablePane>        <columns>            <TablePane.Column width="1*"/>        </columns>         <TablePane.Row height="-1">            <Border styles="{color:'#999999'}">            	<TablePane>            		<columns>            			<TablePane.Column width="-1"/>            			<TablePane.Column width="1*"/>            			<TablePane.Column width="-1"/>        			</columns>        			<TablePane.Row height="-1">        				<Label bxml:id="dateLabel" />        				<Label bxml:id="authorLabel" />        				<PushButton buttonData=">" styles="{minimumAspectRatio:1.5}"/>         			</TablePane.Row>        		</TablePane>            </Border>		</TablePane.Row>				<TablePane.Row height="1*">            <Border styles="{color:'#999999'}">            	<BoxPane styles="{padding:6, verticalAlignment
 :'top'}">        			<Label bxml:id="summaryLabel" text="Summary"/>        			<TextArea bxml:id="descriptionTextArea" minimumHeight="2"/>    			</BoxPane>            </Border>		</TablePane.Row>		    </TablePane>    </BoxPane></thumbnail:CommentPane>
if I use BXML serializer, i can load one into my scroll pane with setView.  but when I load a second one, I have an error message "ID dateLabel is already in use".
I can't use bxml:include in bxml file because I don't know until I read the database.
Hopefully, that's clear.
Brendan



> Date: Sat, 17 Sep 2011 17:45:04 +0700
> Subject: Re: How to dynamically add component to window
> From: cbartlett.x@gmail.com
> To: user@pivot.apache.org
> 
> Here is a test that shows how to use the 'inline' flag to include BXML.
> http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/include_test.bxml
> http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/include_test.content.bxml
> 
> On 17 September 2011 17:42, Chris Bartlett <cb...@gmail.com> wrote:
> &g t; 2011/9/17 Brendan cheng <cc...@hotmail.com>:
> >> Actually, I was trying to inject a series of box pane from the bxml files.
> > Are you talking about using BXML's 'include' functionality?
> > http://pivot.apache.org/tutorials/bxml-primer.html
> >
> > If you are, then you can include the same BXML fragments multiple
> > times (or any fragments, including ones where the BXML IDs of
> > Components might clash) by using the inline flag
> > <bxml:include src="foo.bxml" inline="true"/>

 		 	   		  

Re: How to dynamically add component to window

Posted by Greg Brown <gk...@verizon.net>.
Sounds like this might be a good use case for a custom list view item renderer. Here is an example:

http://pivot.apache.org/tutorials/web-queries.html

On Sep 17, 2011, at 7:58 AM, Brendan cheng wrote:

> My program need to show a series of comment displayed in a sroll pane somewhere in my main window.
> I created a bxml file called CommentPane which take three variables Date, Author and comment.
> And the list of comments stored in database.
> 
> so my CommentPane code like this:
> <thumbnail:CommentPane
>     xmlns:bxml="http://pivot.apache.org/bxml"
>     xmlns:thumbnail="hk.itags.gui.thumbnail"
>     xmlns="org.apache.pivot.wtk">
>     <BoxPane>
>     <TablePane>
>         <columns>
>             <TablePane.Column width="1*"/>
>         </columns>
>  
>         <TablePane.Row height="-1">
>             <Border styles="{color:'#999999'}">
>             	<TablePane>
>             		<columns>
>             			<TablePane.Column width="-1"/>
>             			<TablePane.Column width="1*"/>
>             			<TablePane.Column width="-1"/>
>         			</columns>
>         			<TablePane.Row height="-1">
>         				<Label bxml:id="dateLabel" />
>         				<Label bxml:id="authorLabel" />
>         				<PushButton buttonData=">" styles="{minimumAspectRatio:1.5}"/> 
>         			</TablePane.Row>
>         		</TablePane>
>             </Border>
> 		</TablePane.Row>
> 		
> 		<TablePane.Row height="1*">
>             <Border styles="{color:'#999999'}">
>             	<BoxPane styles="{padding:6, verticalAlignment:'top'}">
>         			<Label bxml:id="summaryLabel" text="Summary"/>
>         			<TextArea bxml:id="descriptionTextArea" minimumHeight="2"/>
>     			</BoxPane>
>             </Border>
> 		</TablePane.Row>
> 		
>     </TablePane>
>     </BoxPane>
> </thumbnail:CommentPane>
> 
> if I use BXML serializer, i can load one into my scroll pane with setView.  but when I load a second one, I have an error message "ID dateLabel is already in use".
> 
> I can't use bxml:include in bxml file because I don't know until I read the database.
> 
> Hopefully, that's clear.
> 
> Brendan
> 
> 
> 
> 
> > Date: Sat, 17 Sep 2011 17:45:04 +0700
> > Subject: Re: How to dynamically add component to window
> > From: cbartlett.x@gmail.com
> > To: user@pivot.apache.org
> > 
> > Here is a test that shows how to use the 'inline' flag to include BXML.
> > http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/include_test.bxml
> > http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/include_test.content.bxml
> > 
> > On 17 September 2011 17:42, Chris Bartlett <cb...@gmail.com> wrote:
> > &g t; 2011/9/17 Brendan cheng <cc...@hotmail.com>:
> > >> Actually, I was trying to inject a series of box pane from the bxml files.
> > > Are you talking about using BXML's 'include' functionality?
> > > http://pivot.apache.org/tutorials/bxml-primer.html
> > >
> > > If you are, then you can include the same BXML fragments multiple
> > > times (or any fragments, including ones where the BXML IDs of
> > > Components might clash) by using the inline flag
> > > <bxml:include src="foo.bxml" inline="true"/>


RE: How to dynamically add component to window

Posted by Brendan cheng <cc...@hotmail.com>.
My program need to show a series of comment displayed in a sroll pane somewhere in my main window.I created a bxml file called CommentPane which take three variables Date, Author and comment.And the list of comments stored in database.
so my CommentPane code like this:<thumbnail:CommentPane
    xmlns:bxml="http://pivot.apache.org/bxml"
    xmlns:thumbnail="hk.itags.gui.thumbnail"
    xmlns="org.apache.pivot.wtk">
    <BoxPane>
    <TablePane>
        <columns>
            <TablePane.Column width="1*"/>
        </columns>
 
        <TablePane.Row height="-1">
            <Border styles="{color:'#999999'}">
            	<TablePane>
            		<columns>
            			<TablePane.Column width="-1"/>
            			<TablePane.Column width="1*"/>
            			<TablePane.Column width="-1"/>
        			</columns>
        			<TablePane.Row height="-1">
        				<Label bxml:id="dateLabel" />
        				<Label bxml:id="authorLabel" />
        				<PushButton buttonData=">" styles="{minimumAspectRatio:1.5}"/> 
        			</TablePane.Row>
        		</TablePane>
            </Border>
		</TablePane.Row>
		
		<TablePane.Row height="1*">
            <Border styles="{color:'#999999'}">
            	<BoxPane styles="{padding:6, verticalAlignment:'top'}">
        			<Label bxml:id="summaryLabel" text="Summary"/>
        			<TextArea bxml:id="descriptionTextArea" minimumHeight="2"/>
    			</BoxPane>
            </Border>
		</TablePane.Row>
		
    </TablePane>
    </BoxPane>
</thumbnail:CommentPane>
if I use BXML serializer, i can load one into my scroll pane with setView.  but when I load a second one, I have an error message "ID dateLabel is already in use".
I can't use bxml:include in bxml file because I don't know until I read the database.
Hopefully, that's clear.
Brendan



> Date: Sat, 17 Sep 2011 17:45:04 +0700
> Subject: Re: How to dynamically add component to window
> From: cbartlett.x@gmail.com
> To: user@pivot.apache.org
> 
> Here is a test that shows how to use the 'inline' flag to include BXML.
> http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/include_test.bxml
> http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/include_test.content.bxml
> 
> On 17 September 2011 17:42, Chris Bartlett <cb...@gmail.com> wrote:
> > 2011/9/17 Brendan cheng <cc...@hotmail.com>:
> >> Actually, I was trying to inject a series of box pane from the bxml files.
> > Are you talking about using BXML's 'include' functionality?
> > http://pivot.apache.org/tutorials/bxml-primer.html
> >
> > If you are, then you can include the same BXML fragments multiple
> > times (or any fragments, including ones where the BXML IDs of
> > Components might clash) by using the inline flag
> > <bxml:include src="foo.bxml" inline="true"/>
 		 	   		  

Re: How to dynamically add component to window

Posted by Chris Bartlett <cb...@gmail.com>.
Here is a test that shows how to use the 'inline' flag to include BXML.
http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/include_test.bxml
http://svn.apache.org/repos/asf/pivot/trunk/tests/src/org/apache/pivot/tests/include_test.content.bxml

On 17 September 2011 17:42, Chris Bartlett <cb...@gmail.com> wrote:
> 2011/9/17 Brendan cheng <cc...@hotmail.com>:
>> Actually, I was trying to inject a series of box pane from the bxml files.
> Are you talking about using BXML's 'include' functionality?
> http://pivot.apache.org/tutorials/bxml-primer.html
>
> If you are, then you can include the same BXML fragments multiple
> times (or any fragments, including ones where the BXML IDs of
> Components might clash) by using the inline flag
> <bxml:include src="foo.bxml" inline="true"/>

Re: How to dynamically add component to window

Posted by Chris Bartlett <cb...@gmail.com>.
I don't really understand what you are trying to do, and I can't tell
if you have code that doesn't work or if you are just asking a
question about how to 'inject a series of box pane from the bxml
files'.

If you are seeing Exceptions thrown somewhere, please post them to the
list, and if possible, include a small example application
demonstrating the problem.


2011/9/17 Brendan cheng <cc...@hotmail.com>:
> Actually, I was trying to inject a series of box pane from the bxml files.
Are you talking about using BXML's 'include' functionality?
http://pivot.apache.org/tutorials/bxml-primer.html

If you are, then you can include the same BXML fragments multiple
times (or any fragments, including ones where the BXML IDs of
Components might clash) by using the inline flag
<bxml:include src="foo.bxml" inline="true"/>

> Do I have to use the bxml Serializer repeatedly?
> Or do I have to use java code instead of?  how to handle the variables in
> BXML because they have the same names.?
Or are you talking about loading BXML files in your Java code (using
BXMLSerializer) and then doing something with them?

Here is an old mailing list thread which talks about reusing
BXMLSerializer to load multiple BMXL files.
http://apache-pivot-users.399431.n3.nabble.com/bxml-id-scoping-tp2838043p2838043.html

Chris

RE: How to dynamically add component to window

Posted by Brendan cheng <cc...@hotmail.com>.
Chris,
Thanks so much and it works!
Actually, I was trying to inject a series of box pane from the bxml files.  Do I have to use the bxml Serializer repeatedly?Or do I have to use java code instead of?  how to handle the variables in BXML because they have the same names.?
Brendan 
> Date: Sat, 17 Sep 2011 16:27:47 +0700
> Subject: Re: How to dynamically add component to window
> From: cbartlett.x@gmail.com
> To: user@pivot.apache.org
> 
> Brendan,
> 
> I think this is your problem.
> >         rightScrollPane.add(commentPane);
> 
> Try replacing it with
> rightScrollPane.setView(commentPane);
> 
> 
> Some background if you are interested ...
> 
> ScrollPane is an instance of ViewPort, which is in turn an instance of
> Container. http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/ScrollPane.html
> http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Viewport.html
> http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Container.html
> 
> Some Containers (like BoxPane) simply display whatever child
> Components were added to the Sequence<Component> that Container
> provides.
> http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/BoxPane.html
> http://pivot.apache.org/2.0/docs/api/org/apache/pivot/collections/Sequence.html
> 
> Others Containers (like ScrollPane) are a little more complex and can
> display additional UI elements.  In the case of ScrollPane, it can
> display a 'rowHeader', 'columnHeader', and 'corner' as well as a
> 'view'.
> http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/ScrollPane.html#setRowHeader(org.apache.pivot.wtk.Component)
> http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/ScrollPane.html#setColumnHeader(org.apache.pivot.wtk.Component)
> http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/ScrollPane.html#setCorner(org.apache.pivot.wtk.Component)
> http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Viewport.html#setView(org.apache.pivot.wtk.Component)
> 
> ScrollPane therefore needs to manage the Sequence<Component> provided
> by Container, so you need to tell it what to do with the Components
> that you give to it, rather than adding them to the
> Sequence<Component> directly (which is what
> rightScrollPane.add(commentPane) looks to be doing).
> 
> In your example you want to show your 'rightScrollPane' Component as
> the ScrollPane's 'view'.
> 'view' is the default property of ScrollPane (inherited from
> ViewPort).  This is defined via the @DefaultProperty annotation.
> http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/Viewport.java
> 
> Unfortunately, the DefaultProperty annotation is not shown in the
> Pivot 2.0 Javadocs, but it is always visible in the source code.  From
> 2.0.1 (which will hopefully be released soon) the DefaultProperty
> annotation *will* be visible in the Javadocs.
> 
> Chris
> 
> 2011/9/17 Brendan cheng <cc...@hotmail.com>:
> > Hi,
> > I must say I'm totally new to Pivot.  I'm trying add a box pane to my
> > window's scroll pane but even the code compiled properly, the box pane just
> > doesn't show up.
> > Here is the snippet from my main program.
> >
> > @Override
> >
> >     public void startup(Display display, Map<String, String> properties)
> > throws Exception {
> >
> >         String language = properties.get(LANGUAGE_KEY);
> >
> >         Locale locale = (language == null) ? Locale.getDefault() : new
> > Locale(language);
> >
> >         Resources resources = new Resources(ClientWindow.class.getName(),
> > locale);
> >
> >         BXMLSerializer bxmlSerializer = new BXMLSerializer();
> >
> >         window =
> > (ClientWindow)bxmlSerializer.readObject(getClass().getResource("client_window.bxml"),
> >
> >             resources);
> >
> >         ScrollPane rightScrollPane = (ScrollPane)
> > bxmlSerializer.getNamespace().get("rightScrollPane");
> >
> >         BoxPane commentPane = null;
> >
> >         try {
> >
> > commentPane =
> > (CommentPane)bxmlSerializer.readObject(getClass().getResource("thumbnail/comment_pane.bxml"),
> >
> >     resources);
> >
> > } catch (IOException e) {
> >
> > e.printStackTrace();
> >
> > } catch (SerializationException e) {
> >
> > e.printStackTrace();
> >
> > }
> >
> >         rightScrollPane.add(commentPane);
> >
> >         window.open(display);(display);
> >
> > What do you recommend to do this job in pivot?
> >
> > Thanks in advance!
> >
> > Brendan
 		 	   		  

Re: How to dynamically add component to window

Posted by Chris Bartlett <cb...@gmail.com>.
Brendan,

I think this is your problem.
>         rightScrollPane.add(commentPane);

Try replacing it with
rightScrollPane.setView(commentPane);


Some background if you are interested ...

ScrollPane is an instance of ViewPort, which is in turn an instance of
Container. http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/ScrollPane.html
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Viewport.html
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Container.html

Some Containers (like BoxPane) simply display whatever child
Components were added to the Sequence<Component> that Container
provides.
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/BoxPane.html
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/collections/Sequence.html

Others Containers (like ScrollPane) are a little more complex and can
display additional UI elements.  In the case of ScrollPane, it can
display a 'rowHeader', 'columnHeader', and 'corner' as well as a
'view'.
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/ScrollPane.html#setRowHeader(org.apache.pivot.wtk.Component)
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/ScrollPane.html#setColumnHeader(org.apache.pivot.wtk.Component)
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/ScrollPane.html#setCorner(org.apache.pivot.wtk.Component)
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Viewport.html#setView(org.apache.pivot.wtk.Component)

ScrollPane therefore needs to manage the Sequence<Component> provided
by Container, so you need to tell it what to do with the Components
that you give to it, rather than adding them to the
Sequence<Component> directly (which is what
rightScrollPane.add(commentPane) looks to be doing).

In your example you want to show your 'rightScrollPane' Component as
the ScrollPane's 'view'.
'view' is the default property of ScrollPane (inherited from
ViewPort).  This is defined via the @DefaultProperty annotation.
http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/Viewport.java

Unfortunately, the DefaultProperty annotation is not shown in the
Pivot 2.0 Javadocs, but it is always visible in the source code.  From
2.0.1 (which will hopefully be released soon) the DefaultProperty
annotation *will* be visible in the Javadocs.

Chris

2011/9/17 Brendan cheng <cc...@hotmail.com>:
> Hi,
> I must say I'm totally new to Pivot.  I'm trying add a box pane to my
> window's scroll pane but even the code compiled properly, the box pane just
> doesn't show up.
> Here is the snippet from my main program.
>
> @Override
>
>     public void startup(Display display, Map<String, String> properties)
> throws Exception {
>
>         String language = properties.get(LANGUAGE_KEY);
>
>         Locale locale = (language == null) ? Locale.getDefault() : new
> Locale(language);
>
>         Resources resources = new Resources(ClientWindow.class.getName(),
> locale);
>
>         BXMLSerializer bxmlSerializer = new BXMLSerializer();
>
>         window =
> (ClientWindow)bxmlSerializer.readObject(getClass().getResource("client_window.bxml"),
>
>             resources);
>
>         ScrollPane rightScrollPane = (ScrollPane)
> bxmlSerializer.getNamespace().get("rightScrollPane");
>
>         BoxPane commentPane = null;
>
>         try {
>
> commentPane =
> (CommentPane)bxmlSerializer.readObject(getClass().getResource("thumbnail/comment_pane.bxml"),
>
>     resources);
>
> } catch (IOException e) {
>
> e.printStackTrace();
>
> } catch (SerializationException e) {
>
> e.printStackTrace();
>
> }
>
>         rightScrollPane.add(commentPane);
>
>         window.open(display);(display);
>
> What do you recommend to do this job in pivot?
>
> Thanks in advance!
>
> Brendan