0

Creating Listbox in java

asked 2010-12-09 01:13:45 +0800

Naveen gravatar image Naveen
42

hello,
i tried the example given in http://www.zkoss.org/forum/listComment/10452 and i slightly altered it to add one more header and how can i set values to that using arraylist

<window id="win" title="Hello World!!" border="normal" width="200px" apply="com.test.tets">

	<listbox id="listbox" >
	<listhead>
	<listheader label="Name"></listheader>
	<listheader label="Age"></listheader>
	</listhead>
	</listbox>
	
	<button label="add" onClick="win$composer.add()" />	
	<button label="remove" onClick="win$composer.remove()" />	

</window>

package com.test;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.*;
public class tets extends GenericForwardComposer {
	
	protected Listbox listbox; // autowired
	private ListModelList list; // the model of the listbox
	
	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		
		List<String> data = new ArrayList<String>();
		data.add("Hello");
		data.add("World");
		data.add("!");
		
		list = new ListModelList(data, true); // if live is set to true the data list will also be modified
		
		listbox.setModel(list);
	}
	
	public void remove() {
		if(list.size() > 0)
			list.remove(0);
	}
	
	public void add() {
		list.add("TEST");
	}
	
}

how to add one more column in the listbox....

delete flag offensive retag edit

0 Replies

Sort by ยป oldest newest

answered 2010-12-09 03:44:59 +0800

Meko gravatar image Meko
24

updated 2010-12-09 03:45:13 +0800

I think you forgot to use listcell. if you have 2 header then should use 2 listcell item.

		<listbox fixedLayout="true" id="box" mold="paging"
					pageSize="31" rows="5" height="500px"
					model="@{win$composer.AllProducts}"
					selectedItem="@{win$composer.current}">

					<listhead>
						<listheader width="20px" id="checkbox" />
						<listheader width="100px" id="productName"
							label="Product_Name" sort="auto(name)" />
						<listheader id="category" label="Category"
							width="50px" sort="auto(cat)" />
						<listheader id="quantity" label="Quant"
							width="50px" sort="auto(quant)" />
						<listheader id="cDate" label="Date" width="90px"
							sort="auto(date)" />
					</listhead>



					<listitem self="@{each='event'}" value="@{event}">
						<listcell>
							<checkbox id="cbox"
								forward="onCheck=onChecked" />
						</listcell>
						<listcell label="@{event.name}" />
						<listcell label="@{event.cat}" />
						<listcell label="@{event.quant}" />
						<listcell label="@{event.date}" />



					</listitem>

				</listbox>

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-12-09 01:13:45 +0800

Seen: 523 times

Last updated: Jan 04 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More