Hi!
I would like to add ActionListener to buttons stored in JToolBar. However, if I'm using the code bellow, then I could add only MouseListener ("addActionListener" doesn't work). So, is it possible to somehow add ActionListener? Thanks a lot!
JToolBar toolBarUpdateDocs = new BrowserToolBar();
toolBarUpdateDocs.setFloatable(false);
toolBarUpdateDocs.getComponent(i).addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("Ok");
}
});
...
private class BrowserToolBar extends JToolBar {
private BrowserToolBar() {
String[] imageFiles =
{ "add.png", "del.png", "search.png" };
String[] toolbarLabels =
{ "Add", "Delete", "Find" };
Insets margins = new Insets(0, 0, 0, 0);
for(int i=0; i<toolbarLabels.length; i++) {
ToolBarButton but = new ToolBarButton("src/icons/" + imageFiles[i]);
but.setToolTipText(toolbarLabels[i]);
but.setMargin(margins);
add(but);
}
}
}