0

Create Grid in Java

asked 2015-06-25 14:33:37 +0800

tylero gravatar image tylero
1 2

I would like to create a grid completely in Java, but am struggling to find how to do this. I've read that it is possible to implement all zk code completely in Java, but I'm unsure what to put in an index.zul and grid.java file that will accomplish this.

delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2015-06-25 14:57:15 +0800

Darksu gravatar image Darksu
1991 1 4

Hello tylero,

At the following post you can find a pretty good example on how to dynamically create a listbox (Creating a grid is pretty similar, you just have to set the respective columns, and rows instead of listhead's, listitem's, and listcell's )

http://forum.zkoss.org/question/32343/programmatically-creation-of-the-list-box/

And some more examples:

http://forum.zkoss.org/question/86341/create-grid-columns-in-java-only/

http://forum.zkoss.org/question/77150/how-to-create-a-zk-grid-in-pure-java/

As for the index zul, i would put at least the window id, so that in the controller you will create the grid and then set as it's parent the window.

Best Regards,

Darksu

link publish delete flag offensive edit
0

answered 2015-06-26 11:27:49 +0800

czerpek gravatar image czerpek
1
http://www.wniosek-o-kred...

interesting post

link publish delete flag offensive edit
0

answered 2015-06-26 13:21:33 +0800

claudioveryant gravatar image claudioveryant
9 1
/**
 * see:
 * books.zkoss.org/wiki/Small_Talks/2013/January/Building_User_Interface_Programmatically_with_Richlet
 * - put this source under WEB-INF/sources;
 * - compile LoadGrid.java using ZK library;
 * - put the LoadGrid.class generated in WEB-INF/classes
 * - put the following lines in WEB-INF/zk.xml:
* <richlet> * <richlet-name>LoadGrid</richlet-name> * <richlet-class>LoadGrid</richlet-class> * </richlet> * <richlet-mapping> * <richlet-name>LoadGrid</richlet-name> * <url-pattern>/LoadGrid</url-pattern> * </richlet-mapping> * <servlet-mapping>
* - Uncomment in WEB-INF/web.xml the following lines to enable richlet
* <servlet-mapping> * <servlet-name>zkLoader</servlet-name> * <url-pattern>/zk/*</url-pattern> * </servlet-mapping>
* - starts Tomcat; * - type in the Browser:
* http://<address>:8080/<your tomcat webapps HOME project>/zk/LoadGrid */ import java.util.*; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.GenericRichlet; import org.zkoss.zk.ui.Page; import org.zkoss.zul.Borderlayout; import org.zkoss.zul.*; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.impl.XulElement; import org.zkoss.zul.event.ListDataEvent; public class LoadGrid extends GenericRichlet { //Richlet// private static int numrighe = 56; private static int numcolonne = 10; String[][] model = new String[numrighe][numcolonne]; Grid gd; MyModel mm; int conta = 0; private class MyModel extends AbstractListModel implements ListModelExt { String[][] mymodel = new String[numrighe][numcolonne]; int nr; int nc; public MyModel(int nr, int nc) { mymodel = new String[nr][nc]; this.nr = nr; this.nc = nc; } public String getValueAt(int r, int c) { return mymodel[r][c]; } public Object getElementAt(int r) { return mymodel[r]; } public int getSize() { return nr; } public String getSortDirection(java.util.Comparator cmp) { return "natural"; } public void sort(java.util.Comparator cmp, boolean asc) { } public void fireTableRowsInserted(int start, int end) { System.out.println("====>FTROWSINSERTED ["+start+"] ["+end+"]"); fireEvent(ListDataEvent.INTERVAL_ADDED, start, end); } public void fireTableRowsDeleted(int start, int end) { System.out.println("====>FTROWSDELETED ["+start+"] ["+end+"]"); fireEvent(ListDataEvent.INTERVAL_REMOVED, start, end); } } public class MyRowRenderer implements RowRenderer { Vector righe = new Vector(); boolean vf; public MyRowRenderer (boolean vf) { this.vf = vf; for(int j = 0; j < model.length; ++j) righe.add(model[j]); } public void render(Row row, java.lang.Object data, int k) { String []datav = (String[])data; for (int i = 0; i < datav.length; i++) { Cell hb = null; Textbox tb = null; hb = new Cell(); tb = new Textbox(); tb.setText(new Integer(conta).toString() + "-" + new Integer(k).toString()+ "-" + new Integer(i).toString()); tb.setParent(hb); hb.setParent(row); if (vf) { hb.setHflex("1"); tb.setHflex("1"); } else { hb.setWidth("100%"); tb.setWidth("120px"); } tb.setHeight("30px"); hb.setHeight("30px"); row.setHeight("30px"); } } } public void service(Page p) { final Desktop dsk = Executions.getCurrent().getDesktop(); final Page page = p; Window w = null; int topwin = 30; w = new Window("LoadGrid", "overlapped", true); w.setHeight("600px"); w.setWidth("800px"); w.setStyle("position:absolute;border:solid 1px;"); w.setTop(new Integer(topwin)+"px"); w.setLeft("20px"); w.setPage(page); topwin += 20; Columns cls = null; Column c = null; gd = new Grid(); gd.setStyle("position:absolute;margin:4px;color:cyan;font-family:Gill Sans MT;font-size:14pt;"); gd.setLeft("50px"); gd.setTop("100px"); gd.setWidth("650px"); gd.setHeight("450px"); gd.setParent(w); cls = new Columns(); cls.setSizable(true); gd.appendChild(cls); for (int i = 0; i < numcolonne; i++) { c = new Column(); c.setLabel(new Integer(i).toString()); c.setParent(cls); } mm = new MyModel(numrighe, numcolonne); gd.setModel(mm); gd.setRowRenderer(new MyRowRenderer(false)); } }
link publish delete flag offensive edit
Your answer
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
1 follower

RSS

Stats

Asked: 2015-06-25 14:33:37 +0800

Seen: 52 times

Last updated: Jun 26 '15

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