X

Geertjan's Blog

  • December 3, 2008

Creating a NetBeans Platform Toolbar in 6.5

Geertjan Wielenga
Product Manager
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.

Join the discussion

Comments ( 6 )
  • RunningTracker Sunday, December 7, 2008

    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 ?


  • sinema izle Tuesday, March 10, 2009

    thank u. nice work.


  • guest Monday, May 25, 2009

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


  • Geertjan Monday, May 25, 2009

    Right click and choose Run.


  • Vintesh Wednesday, August 17, 2011

    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");

    }

    }


  • Geertjan Wednesday, August 17, 2011

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


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services