0

how to insert "after" a component? (向指定控件后面插入一个兄弟控件)

asked 2019-06-17 19:37:27 +0800

xuesong gravatar image xuesong
101 2

updated 2019-06-19 10:18:20 +0800

cor3000 gravatar image cor3000
6280 2 7

实例如下,现在想在txt2控件后插入一个div,请问可以实现吗? 目前ZK提供的方法有appendChild、beforeChildAdded、insertBefore,无法实现。

<div>
<textbox id="txt1"/>
<textbox id="txt2"/>
<textbox id="txt3"/>
</div>

EDIT: (google translation) The example is as follows, now I want to insert a div after the txt2 control, can I achieve it?

delete flag offensive retag edit

1 Answer

Sort by » oldest newest most voted
0

answered 2019-06-18 14:23:08 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2019-06-19 09:29:17 +0800

As shown in this example you can add a component after another one, by inserting it before its next sibling. You have to call the method from the parent component:

txt2.getParent().insertBefore(new Label("inserted"), txt2.getNextSibling())

EDIT:

If the nextsibling doesn't exist it will return null. Calling parent.insertBefore(comp, null) is equivalent to calling parent.appendChild(comp), both will append to the end. In your example after txt3

Please also refer to the related java docs:

https://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/Component.html#insertBefore-org.zkoss.zk.ui.Component-org.zkoss.zk.ui.Component-

link publish delete flag offensive edit

Comments

如果此时还没有NextSibling控件呢?

xuesong ( 2019-06-18 22:36:16 +0800 )edit

replied above...

cor3000 ( 2019-06-19 09:29:44 +0800 )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
2 followers

RSS

Stats

Asked: 2019-06-17 19:37:27 +0800

Seen: 26 times

Last updated: Jul 30 '19

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