-
Notifications
You must be signed in to change notification settings - Fork 1
DevFaqWindowsNoActionsOnToolbars
There is no canonical (or pretty) way to do this, but there is a hack you can do - it works in NetBeans 5.0, 5.5 and 6.x (and probably earlier versions but this wasn’t tested).
Create the following ModuleInstall
class (remember to add a reference to it in the module manifest, e.g.
OpenIDE-Module-Install: org/netbeans/modules/toolbarthing/Installer.class
If you are using 5.0’s update 1 of module development support or later, you can just use New File > NetBeans Plug-In Modules > Module Installer):
package org.netbeans.modules.toolbarthing;
import java.awt.Component;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JToolBar;
import org.openide.modules.ModuleInstall;
import org.openide.windows.WindowManager;
public class Installer extends ModuleInstall implements Runnable {
public void restored() {
WindowManager.getDefault().invokeWhenUIReady(this);
}
public void run() {
JToolBar[] tb = findToolbars();
for (int i = 0; i < tb.length; i++) {
processToolbar (tb[I]);
}
}
private JToolBar[] findToolbars() {
List l = new ArrayList();
JFrame jf = (JFrame) WindowManager.getDefault().getMainWindow();
findToolbars (jf.getContentPane(), l);
JToolBar[[ | ]] tb = (JToolBar[[ | ]]) l.toArray(new JToolBar[L.size()]);
return tb;
}
private void findToolbars(Component c, List l) {
if (c instanceof JToolBar) {
l.add(c);
} else if (c instanceof Container) {
Component[] cc = ((Container) c).getComponents();
for (int i=0; i < cc.length; i++) {
findToolbars(cc[I], l);
}
}
}
private void processToolbar (JToolBar bar) {
MouseListener[] ml = bar.getMouseListeners();
for (int i = 0; i < ml.length; i++) {
if (ml[I].getClass().getName().indexOf("PopupListener") >= 0) {
bar.removeMouseListener (ml[I]);
}
}
}
}
The above doesn’t seems to work in 6.9.1. This is another similar module installer hack to achieve this:
public class Installer extends ModuleInstall
{
public void restored()
{
removeToolbarPopupMenu();
}
private void removeToolbarPopupMenu()
{
WindowManager.getDefault().invokeWhenUIReady(
new Runnable()
{
@Override
public void run()
{
removeAllPopupListeners(ToolbarPool.getDefault());
}
});
}
private static void removeAllPopupListeners(Component c)
{
if(c instanceof Container)
{
for(Component c2 : ((Container)c).getComponents())
{
for(MouseListener l : c2.getMouseListeners())
{
if(l.getClass().getName().contains("PopupListener"))
{
c2.removeMouseListener(l);
// Uncomment to obtain a similar console output
// Removing: org.openide.awt.ToolbarPool$PopupListener@1535ac from javax.swing.JPanel[...]
// Removing: org.openide.awt.ToolbarPool$PopupListener@1535ac from org.openide.awt.Toolbar[File,...]
//System.out.println("Removing: " + l + " from " + c2);
}
}
findToolbars(c2);
}
}
}
}
The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.
This page was exported from http://wiki.netbeans.org/DevFaqWindowsNoActionsOnToolbars , that was last modified by NetBeans user Adayth on 2011-06-15T11:23:36Z.
NOTE: This document was automatically converted to the AsciiDoc format on 2018-01-26, and needs to be reviewed.
Apache NetBeans is an effort undergoing incubation at The Apache Software Foundation (ASF).
Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects.
While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
This wiki is an experiment pending Apache NetBeans Community approval.