Creating a NetBeans Platform Toolbar in 6.5

Creating a new toolbar for NetBeans IDE is now easy in 6.5. Just use the New Action wizard, which gives you an "ActionListener", and then replace the "ActionListener" implementation with a "Presenter.Toolbar", as shown here:
package org.demo.toolbar;

import java.awt.Component;
import org.openide.util.actions.Presenter;

public final class SomeAction implements Presenter.Toolbar {

    //Here's where you put your panel into the toolbar area:
    @Override
    public Component getToolbarPresenter() {
        return new DemoJPanel();
    }

}

Finally, delete the "instanceCreate" attribute that the New Action wizard created in the layer.xml. Then install and you're done.

Update. See this tutorial for the complete example, the above is partial and incomplete.

Comments:

Thanks for your post. It worked fine.
I have one question: let's say you clicked "New Action", and then you forgot to select the checkbox "Global toolbar button"... at the end of the coding of the class "SomeAction", you start the project and you notice that you forgot to put an instance of "SomeAction" in the toolbar menu. In this case, what do you do ? Do you have to edit the layout.xml file or is there another possibility ?

Posted by RunningTracker on December 06, 2008 at 07:04 PM PST #

thank u. nice work.

Posted by sinema izle on March 10, 2009 at 07:22 AM PDT #

I do not understand what is meant with "install". Can someone explain it to me step by step?

Posted by guest on May 25, 2009 at 03:07 AM PDT #

Right click and choose Run.

Posted by Geertjan on May 25, 2009 at 03:30 AM PDT #

I am trying to call getToolbarPresenter() in the code shown below but i am not able to call. Would u help me out?

import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
import org.openide.util.actions.Presenter;

//public final class DigitalClock extends CallableSystemAction {
//public final class DigitalClock extends AbstractAction implements Presenter.Toolbar {
public final class DigitalClock implements Presenter.Toolbar, ActionListener {

// @Override
// public void performAction() {
// System.out.println("Into performAction");
// }
//
// @Override
// public String getName() {
// return "Clock";
// }
//
// @Override
// public HelpCtx getHelpCtx() {
// throw new UnsupportedOperationException("Not supported yet.");
// }
private static class Clock extends JLabel {

private String pattern;
private Timer timer;
private int delay;

/**
* Constructs a Digital Clock using the given pattern and the default delay.
* @param pattern - the pattern describing the date and time format
*/
public Clock(String pattern) {
this.pattern = pattern;
this.delay = 1000;
createTimer();
timer.start();
}

/**
* Constructs a Digital Clock using the given pattern and delay.
* @param delay - the number of milliseconds between action events
* @param pattern - the pattern describing the date and time format
*/
public Clock(String pattern, int delay) {
this.pattern = pattern;
this.delay = delay;
createTimer();
timer.start();
}

/**
* Constructs a Digital Clock using the default pattern and delay.
*/
public Clock() {
pattern = "hh:mm:ss a";
this.delay = 1000;
createTimer();
timer.start();
}

private void createTimer() {
timer = new Timer(delay, new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
setText(new SimpleDateFormat(pattern).format(new Date()));
}
});
}

public String getPattern() {
return pattern;
}

public void setPattern(String pattern) {
this.pattern = pattern;
}

public Timer getTimer() {
return timer;
}

public int getDelay() {
return delay;
}

public void setDelay(int delay) {
this.delay = delay;
}
// public static void main(String[] args) {
// JFrame frame = new JFrame();
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// frame.setBounds(100, 100, 193, 72);
// JPanel contentPane = new JPanel();
// frame.setContentPane(contentPane);
// contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
//
// Clock digitalClock = new Clock();
// contentPane.add (digitalClock);
// frame.setVisible (true);
//
// }
}

@Override
public Component getToolbarPresenter() {
System.out.println("Into the Toolbar Presenter");
// JFrame frame = new JFrame();
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// frame.setBounds(100, 100, 193, 72);
// JPanel contentPane = new JPanel();
// frame.setContentPane(contentPane);
// contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
//
// Clock digitalClock = new Clock();
// contentPane.add(digitalClock);
// frame.setVisible(true);

JPanel clockPanel = new JPanel();
clockPanel.setPreferredSize(new Dimension(20, 20));
clockPanel.setVisible(true);
clockPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
clockPanel.add(new Clock());
return clockPanel;
}

public void actionPerformed(ActionEvent e) {
System.out.println("TG");
}
}

Posted by Vintesh on August 16, 2011 at 05:33 PM PDT #

Here is the place to ask your questions: dev@platform.netbeans.org

Posted by Geertjan on August 16, 2011 at 08:16 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today