0

Vertically align components in column header?

asked 2012-06-22 07:06:44 +0800

davout gravatar image davout
1435 3 18

For a complex grid/row display I'm having to use the MVC model and this requires that the columns be dynamically created to fit a variable number of data columns.

For each column header I have to create a mixed image + label display like:

Column aColumn = new Column();
aColumn.setAlign("right");
aColumn.setWidth("9%");
aGrid.getColumns().getChildren().add(aColumn);
Hlayout aLayout = new Hlayout();
aLayout.setParent(aColumn);
// show =/-
String anImageStr = null;
if (aNode.isCompressed()) {
	anImageStr = "/image/icon/column_header_compressed.png";
}
else {
	anImageStr = "/image/icon/column_header_expanded.png";
}
Image anImage = new Image(anImageStr);
anImage.addEventListener("onClick", getHeaderImageEventListener());
setComponentNodeID(anImage,aNode.getEntityID());
anImage.setParent(aLayout);
// then title
Label aLabel = new Label(aNode.getEntityTitle());
aLabel.setParent(aLayout);



However, I can't get the image and label to align vertically. Any suggestions?

Also, how can I force a redraw of the entire grid?

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2012-06-26 10:44:25 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi,

From this sample, the label and image is the children of hlayout and hlayout is for 'horizontal' alignment.

You can call grid.invalidate() to redraw it.

Regards,
Ben

link publish delete flag offensive edit

answered 2012-06-26 13:35:58 +0800

davout gravatar image davout
1435 3 18

I've noticed that within 'hlayout' the vertical alignment is fine so long as the image is vertically smaller than the text/label. Is this a bug?

link publish delete flag offensive edit

answered 2012-07-02 08:52:42 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi,

You can try use an outer div to wrap both label and image and then use an inner div to break them as below:

<zk>
	<zscript><![CDATA[
		import org.zkoss.zul.*;
		public void addColumn(Columns columns) {
			Column aColumn = new Column();
			aColumn.setAlign("right");
			aColumn.setWidth("9%");
			columns.getChildren().add(aColumn);

			Hlayout aLayout = new Hlayout();
			Div div = new Div();
			aLayout.setParent(aColumn);
			div.setParent(aLayout);
			new Image("/img/Centigrade-Widget-Icons/ArrowLeftGreen-16x16.png").setParent(div);
			new Div().setParent(div);
			// then title
			new Label("test label").setParent(div);
		}
	]]></zscript>
	<grid>
		<columns onCreate="addColumn(self);" />
	</grid>
</zk>

Regards,
Ben

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: 2012-06-22 07:06:44 +0800

Seen: 205 times

Last updated: Jul 02 '12

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