| // |
| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| // |
| |
| = How can I change my node's appearance? |
| :page-layout: wikidev |
| :page-tags: wiki, devfaq, needsreview |
| :jbake-status: published |
| :keywords: Apache NetBeans wiki DevFaqChangeNodeAppearance |
| :description: Apache NetBeans wiki DevFaqChangeNodeAppearance |
| :toc: left |
| :toc-title: |
| :page-syntax: true |
| :page-wikidevsection: _nodes_and_explorer |
| :page-position: 25 |
| |
| include::front::partial$database.adoc[] |
| |
| It's pretty simple to change the font color, style or weight for your node's label. Simply override `getHtmlDisplayName` and provide some HTML in your return value. (An example can be found in xref:tutorial::tutorials/nbm-nodesapi2.adoc[this] tutorial.) Here is another example: |
| |
| [source,java] |
| ---- |
| |
| public class MovieNode extends AbstractNode { |
| |
| private Movie movie; |
| |
| public MovieNode(Movie key) { |
| super(Children.LEAF, Lookups.fixed(new Object[]{key})); |
| this.movie = key; |
| setName(key.getTitle()); |
| setDisplayName(key.getTitle()); |
| getHandle(); |
| setIconBaseWithExtension("org/nb/marilyn/pics/marilyn.gif"); |
| } |
| |
| @Override |
| public String getHtmlDisplayName() { |
| return "*" + this.getDisplayName() + "*"; |
| } |
| |
| } |
| |
| ---- |
| |
| The javadoc for the HtmlRenderer class link:{apidoclink}org-openide-awt/org/openide/awt/HtmlRenderer.html[explains what subset of HTML is supported]. You can also change the icon's node by overriding various methods such as `getIcon(int type)` or `{getOpenedIcon()`}. |
| |
| It's also possible, but far more difficult, to control other aspects of the node's appearance; for example, drawing a box around the node or changing its background color. To do this you must create or modify the explorer view in which the node is rendered. link:http://openide.netbeans.org/servlets/ReadMsg?list=dev&msgNo=31412[Fabrizio Giudici posted code that illustrates this] on the `dev@openide` list. |