0

Fill a combobox with a local folder

asked 2010-05-04 09:37:53 +0800

houcine gravatar image houcine
108 1 1

hi,

I have a combobox and I want to fill it with images, it has been filled by icons names but the images will not be displayed
knowing that I get these images from a local folder.

public void appendList(){
File f = new File(System.getProperty("folderDirectory")+"/"+folderName);
if(f.exists()){
String[] files = f.list();
for (String fil:files) {
Comboitem item = new Comboitem(fil);
item.setImage(fil);
list.appendChild(item);
}

}
}
can you help me?

Thanks in advance.

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2010-05-04 11:33:49 +0800

houcine gravatar image houcine
108 1 1

Any idea?

link publish delete flag offensive edit

answered 2010-05-04 14:20:02 +0800

YamilBracho gravatar image YamilBracho
1722 2

Maybe you have to create a RowRenderer

link publish delete flag offensive edit

answered 2010-05-05 03:23:01 +0800

houcine gravatar image houcine
108 1 1

How can i create it?

link publish delete flag offensive edit

answered 2010-05-05 08:36:24 +0800

YamilBracho gravatar image YamilBracho
1722 2

See these links :
- http://www.zkoss.org/smalltalks/livedata/livedataforgrid.dsp
- http://www.zkoss.org/forum/listComment/5351
- http://www.zkoss.org/javadoc/5.0/zk/org/zkoss/zul/RowRenderer.html

link publish delete flag offensive edit

answered 2010-05-05 08:48:34 +0800

houcine gravatar image houcine
108 1 1

I tried, but it did not work!!
I don't think that is the solution for my problem,
another idea?

link publish delete flag offensive edit

answered 2010-05-05 15:00:36 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-05-05 15:03:29 +0800

If you get the image/icon than it must work like Yamil said!

Bellow are codes as a sample from such an ItemRenderer for a listbox. In one ListCell are an ICON + Label.
You can modify it for working as RowRenderer for a Grid if needed:

/**
 * Copyright 2010 the original author or authors.
 * 
 * This file is part of Zksample2. http://zksample2.sourceforge.net/
 *
 * Zksample2 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Zksample2 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Zksample2.  If not, see <http://www.gnu.org/licenses/gpl.html>.
 */
.  .  .
/**
 * Item renderer for listitems in the listbox.
 * 
 * @author bbruhns
 * @author sgerth
 * 
 */
public class SecLoginlogStatisticTotalListModelItemRenderer implements ListitemRenderer, Serializable {

	private static final long serialVersionUID = 1L;
	private transient static final Logger logger = Logger.getLogger(SecLoginlogStatisticTotalListModelItemRenderer.class);

	@Override
	public void render(Listitem item, Object data) throws Exception {

		DummyBean dummyBean = (DummyBean) data;

		if (logger.isDebugEnabled()) {
			// logger.debug("--> " + dummyBean.getCountry());
		}

		Listcell lc;

		lc = new Listcell();
		Hbox hbox = new Hbox();
		hbox.setParent(lc);

		/* Flag-image */
--->		Image img = new Image();
		String path = "/images/countrycode_flags/";
		String flag = StringUtils.lowerCase(dummyBean.getCountry()) + ".gif";
		img.setSrc(path + flag);
		hbox.appendChild(img);

		Separator sep = new Separator();
		hbox.appendChild(sep);

		/* Country */
		Label label = new Label();
		label.setValue(dummyBean.getCountry());
		hbox.appendChild(label);
		lc.setParent(item);

		lc = new Listcell(dummyBean.getCountryName());
		lc.setParent(item);

		lc = new Listcell(dummyBean.getTotalCount().toString());
		lc.setStyle("text-align: right");
		lc.setParent(item);

		item.setAttribute("data", data);
		// ComponentsCtrl.applyForward(img, "onClick=onImageClicked");
		// ComponentsCtrl.applyForward(item, "onClick=onClicked");
		// ComponentsCtrl.applyForward(item, "onDoubleClick=onDoubleClicked");

	}
}

best
Stephan

link publish delete flag offensive edit

answered 2010-05-06 08:04:09 +0800

houcine gravatar image houcine
108 1 1

updated 2010-05-06 08:05:37 +0800

I want to use the configuration in:
D:\jboss\jboss-4.2.3.GA\server\default\deploy\jboss-web.deployer/server.xml

<Context path="/image"
docBase="D:/folder/image"
reloadable="true">
</Context>

public void appendList(){
File f = new File(System.getProperty("image");
if(f.exists()){
String[] files = f.list();
for (String fil:files) {
Comboitem item = new Comboitem(fil);
item.setImage(fil);
list.appendChild(item);
}
}
}

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-05-04 09:37:53 +0800

Seen: 481 times

Last updated: May 06 '10

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