Programmatically setStyle on MenuItem (bold?)

asked 2015-10-07 16:12:17 +0800

rickcr gravatar image rickcr
704 7

In my view model, I'm programmatically creating my menupopup. One of the menuitems I'd like to make appear bold. When I try the following style application it's not working:

Menuitem idItem = new Menuitem("ID: "+content.getId());

Note, the API says for setStyle is http://www.zkoss.org/javadoc/8.0.0-RC/zk/org/zkoss/zk/ui/HtmlBasedComponent.html#setStyle(java.lang.String) It just says:

"Sets the CSS style."

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2015-10-08 15:14:18 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

You can define a class name bold into the <style> component or a CSS file as below.

<style> .bold .z-menuitem-text { font-weight: bold} </style>

and in the java code to use idItem.setSclass("bold") instead.

link publish delete flag offensive edit


Thanks! Works great. And THANKS for your IDEA plugin! Loving that plugin! Keep up the great work on it.

rickcr ( 2015-10-08 16:01:12 +0800 )edit

Although it still makes me wonder what setStyle is used for?

rickcr ( 2015-10-08 16:16:13 +0800 )edit

answered 2016-09-05 10:35:55 +0800

nirmalmandhata gravatar image nirmalmandhata flag of India
2 3

updated 2016-09-05 10:59:44 +0800

If user needs to put some specific style like bold or italic then it is useful, but rather it should work like any style like color, background-color should work eg.

Menuitem idItem = new Menuitem("ID: "+content.getId()); idItem.setStyle("color:red");

When a MenuItem is created then in DOM it creates

li tag>
anchor tag>
i tag start & end
span tag start> ID: span tag ends>
anchor tag ends>
li tag ends>

And when we apply style to the MenuItem then it puts the style to li tag> rather than in span tag, hence the style property to the displayed content like Menuitem lable is not applied.

I think its design is like this or we can say its a bug.

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




Asked: 2015-10-07 16:12:17 +0800

Seen: 56 times

Last updated: Sep 05 '16

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