blob: 05b0b63b143fc50bd61ed28b9ad9d959f0393b54 [file] [log] [blame]
//
// 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.
//
= DevFaqChangeMenuItemToolbarAppearanceForAction
:jbake-type: wiki
:jbake-tags: wiki, devfaq, needsreview
:jbake-status: published
:keywords: Apache NetBeans wiki DevFaqChangeMenuItemToolbarAppearanceForAction
:description: Apache NetBeans wiki DevFaqChangeMenuItemToolbarAppearanceForAction
:toc: left
:toc-title:
:syntax: true
=== How do I change the appearance of the menu items and toolbar buttons for my action?
The main menus and toolbars of a NetBeans Platform application are configured based on the contents of folders in the system filesystem. There are many benefits of this approach, such as improved performance since the platform can create all the menus and toolbars without having to actually instantiate the actions with which they are associated.
Because the platform builds the menus and toolbars for you, it might seem like you have little control over how those items appear. In practice, you have a great deal of control over the appearance for any action you create. Typically, actions in a NetBeans platform application which will be shown in the main menu or toolbar extend from `CallableSystemAction`, perhaps indirectly through its `CookieAction` subclass.
In the code you've written for one of these actions, you can override `getMenuPresenter` to change the appearance of the menu item associated with your action and/or override `getToolbarPresenter` to change the appearance of the toolbar component associated with your action.
For example, if you wanted to make the menu item for your action have a blue background and yellow text, you could do something like this:
[source,java]
----
@Override
public JMenuItem getMenuPresenter() {
JMenuItem item = super.getMenuPresenter();
item.setOpaque(true);
item.setBackground(Color.BLUE);
item.setForeground(Color.YELLOW);
return item;
}
----
Note that if you are changing the menu item to support a tooltip, the object returned by `getMenuPresenter` needs a property change listener on the action's `SHORT_DESCRIPTION` so that its tooltip value is updated correctly upon change.
*Note about using alternate components in the main menu:* If you want your action to work properly on Mac OS, you probably don't want to return anything other than a `JMenu` or `JMenuItem` from `getMenuPresenter()` if you implement link:http://www.netbeans.org/download/dev/javadoc/org-openide-util/org/openide/util/actions/Presenter.Menu.html[Presenter.Menu]. In general, Swing allows you to treat menu popups as generic Swing containers you can put what you like into. This is not true at all of the Mac OS screen menu bar - it expects normal menu items, and will not handle unusual contents for menus.
=== Apache Migration Information
The content in this page was kindly donated by Oracle Corp. to the
Apache Software Foundation.
This page was exported from link:http://wiki.netbeans.org/DevFaqChangeMenuItemToolbarAppearanceForAction[http://wiki.netbeans.org/DevFaqChangeMenuItemToolbarAppearanceForAction] ,
that was last modified by NetBeans user Jtulach
on 2010-07-24T20:39:57Z.
*NOTE:* This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.