Java Code Examples for javax.swing.JButton#setAction()

The following examples show how to use javax.swing.JButton#setAction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectInfoPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages({
    "LBL_Loading=<Loading>",
    "LBL_Undefined=<Undefined>"
})
private void setLinkedText(JButton btn, String url, boolean loading) {
    if (url == null) {
        btn.setAction(null);
        if (loading) {
            btn.setText(LBL_Loading());
        } else {
            btn.setText(LBL_Undefined());
        }
        btn.setCursor(null);
    } else {
        btn.setAction(new LinkAction(url));
        btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        btn.setText("<html><a href=\"\">" + url + "</a></html>");
    }
}
 
Example 2
Source File: ActiveBrowserAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    final JButton button = new JButton();
    button.setAction(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            showBrowserPickerPopup( button );
        }
    });
    button.setDisabledIcon(badgeWithArrowIcon(
        ImageUtilities.loadImage(isSmallToolbarIcon() ? DISABLED_SMALL : DISABLED_LARGE)));
    button.setEnabled(false);
    button.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
           if ("PreferredIconSize".equals(evt.getPropertyName())) { // NOI18N
               refreshViewLater(true);
           }
        }
    });
    ProjectBrowserProvider pbp = getBrowserProvider();
    toolbarButton = button;
    updateButton(pbp);
    return button;
}
 
Example 3
Source File: ItemListControl.java    From LoboBrowser with MIT License 6 votes vote down vote up
public ItemListControl(final ItemEditorFactory<T> ief) {
  this.itemEditorFactory = ief;
  this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
  this.comboBox = new JComboBox<>();
  this.comboBox.setPreferredSize(new Dimension(100, 24));
  this.comboBox.setEditable(false);
  final JButton editButton = new JButton();
  editButton.setAction(new EditAction(false));
  editButton.setText("Edit");
  final JButton addButton = new JButton();
  addButton.setAction(new EditAction(true));
  addButton.setText("Add");
  final JButton removeButton = new JButton();
  removeButton.setAction(new RemoveAction());
  removeButton.setText("Remove");
  this.add(this.comboBox);
  this.add(editButton);
  this.add(addButton);
  this.add(removeButton);
}
 
Example 4
Source File: OptionPaneDemo.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
/**
    * Creates the button.
    *
    * @param a the a
    * @return the j button
    */
   public JButton createButton(Action a) {
JButton b = new JButton() {
    public Dimension getMaximumSize() {
	int width = Short.MAX_VALUE;
	int height = super.getMaximumSize().height;
	return new Dimension(width, height);
    }
};
// setting the following client property informs the button to show
// the action text as it's name. The default is to not show the
// action text.
b.putClientProperty("displayActionText", Boolean.TRUE);
b.setAction(a);
// b.setAlignmentX(JButton.CENTER_ALIGNMENT);
return b;
   }
 
Example 5
Source File: RunScriptAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    if (popup != null) {
        JButton button = DropDownButtonFactory.createDropDownButton(
            (ImageIcon) getValue(SMALL_ICON), 
            popup
        );
        button.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
        button.setAction(this);
        return button;
    } else {
        return new JButton(this);
    }
}
 
Example 6
Source File: DownloadDialog.java    From LoboBrowser with MIT License 5 votes vote down vote up
private Component getButtonsPanel() {
  final JButton saveButton = this.saveButton;
  saveButton.setAction(new SaveAction());
  saveButton.setText("Save As...");
  saveButton.setToolTipText("You must select a file before download begins.");

  final JButton closeButton = this.closeButton;
  closeButton.setAction(new CloseAction());
  closeButton.setText("Cancel");

  final JButton openButton = this.openButton;
  openButton.setAction(new OpenAction());
  openButton.setText("Open");

  final JButton openFolderButton = this.openFolderButton;
  openFolderButton.setAction(new OpenFolderAction());
  openFolderButton.setText("Open Folder");

  final Box box = new Box(BoxLayout.X_AXIS);
  // box.setBorder(new BevelBorder(BevelBorder.RAISED));
  box.add(Box.createGlue());
  box.add(openButton);
  box.add(Box.createHorizontalStrut(4));
  box.add(openFolderButton);
  box.add(Box.createHorizontalStrut(4));
  box.add(saveButton);
  box.add(Box.createHorizontalStrut(4));
  box.add(closeButton);
  return box;
}
 
Example 7
Source File: ProgressBarDemo.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
    * Creates the button.
    *
    * @param a the a
    * @return the j button
    */
   public JButton createButton(Action a) {
JButton b = new JButton();
// setting the following client property informs the button to show
// the action text as it's name. The default is to not show the
// action text.
b.putClientProperty("displayActionText", Boolean.TRUE);
b.setAction(a);
return b;
   }
 
Example 8
Source File: ComponentSource.java    From LoboBrowser with MIT License 5 votes vote down vote up
private Component getBackButton() {
  final JButton button = new JButton();
  button.setAction(this.actionPool.backAction);
  button.setIcon(IconFactory.getInstance().getIcon("/images/back.gif"));
  button.setToolTipText("Back");
  return button;
}
 
Example 9
Source File: ComponentSource.java    From LoboBrowser with MIT License 5 votes vote down vote up
private Component getRefreshButton() {
  final JButton button = new JButton();
  button.setAction(this.actionPool.reloadAction);
  button.setIcon(IconFactory.getInstance().getIcon("/images/refresh.gif"));
  button.setToolTipText("Refresh");
  return button;
}
 
Example 10
Source File: ComponentSource.java    From LoboBrowser with MIT License 5 votes vote down vote up
private JButton getRequestManagerButton() {
  final JButton button = new JButton();
  final Action requestManagerAction = this.actionPool.requestManagerAction;
  requestManagerAction.setEnabled(false);
  button.setAction(requestManagerAction);
  button.setToolTipText("Manage requests");
  return button;
}
 
Example 11
Source File: NavigationHistoryForwardAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    if (popupMenu != null) {
        JButton button = DropDownButtonFactory.createDropDownButton(
            (ImageIcon) getValue(SMALL_ICON), 
            popupMenu
        );
        button.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
        button.setAction(this);
        return button;
    } else {
        return new JButton(this);
    }
}
 
Example 12
Source File: AddBookmarkDialog.java    From LoboBrowser with MIT License 5 votes vote down vote up
public AddBookmarkDialog(final Frame owner, final boolean modal, final BookmarkInfo existingInfo) throws HeadlessException {
  super(owner, modal);
  this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  this.url = existingInfo.getUrl();
  this.urlField.setEditable(false);
  this.tagsField.setToolTip("List of keywords separated by blanks.");
  this.urlField.setValue(existingInfo.getUrl().toExternalForm());
  this.titleField.setValue(existingInfo.getTitle());
  this.descriptionField.setValue(existingInfo.getDescription());
  this.tagsField.setValue(existingInfo.getTagsText());
  final Container contentPane = this.getContentPane();
  contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
  final FormPanel fieldsPanel = new FormPanel();
  fieldsPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
  fieldsPanel.addField(this.urlField);
  fieldsPanel.addField(this.titleField);
  fieldsPanel.addField(this.descriptionField);
  fieldsPanel.addField(this.tagsField);

  final Dimension fpps = fieldsPanel.getPreferredSize();
  fieldsPanel.setPreferredSize(new Dimension(400, fpps.height));

  contentPane.add(fieldsPanel);
  final JComponent buttonsPanel = new JPanel();
  buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
  final JButton okButton = new JButton();
  okButton.setAction(new OkAction());
  okButton.setText("Save");
  final JButton cancelButton = new JButton();
  cancelButton.setAction(new CancelAction());
  cancelButton.setText("Cancel");
  buttonsPanel.add(Box.createHorizontalGlue());
  buttonsPanel.add(okButton);
  buttonsPanel.add(Box.createRigidArea(new Dimension(4, 1)));
  buttonsPanel.add(cancelButton);
  buttonsPanel.add(Box.createHorizontalGlue());
  contentPane.add(buttonsPanel);
  contentPane.add(Box.createRigidArea(new Dimension(1, 4)));
}
 
Example 13
Source File: ComponentSource.java    From LoboBrowser with MIT License 5 votes vote down vote up
private Component getGoButton() {
  final JButton button = new JButton();
  button.setAction(this.actionPool.goAction);
  button.setIcon(IconFactory.getInstance().getIcon("/images/go.gif"));
  button.setToolTipText("Navigate to URL");
  return button;
}
 
Example 14
Source File: BrowserPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setActions(AbstractAction[] actions) {
    if(actions != null) {
        controlPanel.buttonPanel.removeAll();
        for (int i = 0; i < actions.length; i++) {
            JButton button = new JButton(); 
            button.setAction(actions[i]);      
            button.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BrowserPanel.class, "CTL_Action_MakeDir"));     // NOI18N
            org.openide.awt.Mnemonics.setLocalizedText(button, org.openide.util.NbBundle.getMessage(BrowserPanel.class, "CTL_Action_MakeDir"));         // NOI18N
            controlPanel.buttonPanel.add(button);                    
        }            
        revalidate();
    }                
}
 
Example 15
Source File: SnippetNavigator.java    From littleluck with Apache License 2.0 4 votes vote down vote up
private void setButtonAction(JButton button, Action action) {
    Icon icon = button.getIcon();
    button.setAction(action);
    button.setHideActionText(true);
    button.setIcon(icon); // icon gets obliterated when action set!
}
 
Example 16
Source File: WindowsDirectoryChooserUI.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
public void installComponents(JFileChooser chooser) {
  this.chooser = (JDirectoryChooser)chooser;

  chooser.setLayout(LookAndFeelTweaks.createBorderLayout());
  chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

  Component accessory = chooser.getAccessory();
  if (accessory != null) {
    chooser.add("North", chooser.getAccessory());
  }

  tree = new JTree() {
    public String getToolTipText(MouseEvent event) {
      String tip = WindowsDirectoryChooserUI.this.getToolTipText(event);
      if (tip == null) {
        return super.getToolTipText(event);
      } else {
        return tip;
      }
    }
  };
  tree.addTreeExpansionListener(new TreeExpansion());

  tree.setModel(new FileSystemTreeModel(chooser.getFileSystemView()));
  tree.setRootVisible(false);
  tree.setShowsRootHandles(false);
  tree.setCellRenderer(new FileSystemTreeRenderer());
  tree.setToolTipText("");

  chooser.add("Center", treeScroll = new JScrollPane(tree));
  treeScroll.setPreferredSize(new Dimension(300, 300));

  approveButton = new JButton();
  approveButton.setAction(getApproveSelectionAction());

  cancelButton = new JButton();
  cancelButton.addActionListener(getCancelSelectionAction());

  buttonPanel = new JPanel(LookAndFeelTweaks.createButtonAreaLayout());
  buttonPanel.add(approveButton);
  buttonPanel.add(cancelButton);
  chooser.add("South", buttonPanel);

  updateView(chooser);
}
 
Example 17
Source File: SnippetNavigator.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
private void setButtonAction(JButton button, Action action) {
    Icon icon = button.getIcon();
    button.setAction(action);
    button.setHideActionText(true);
    button.setIcon(icon); // icon gets obliterated when action set!
}
 
Example 18
Source File: JTagsPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
private void initGUI() {
	setLayout(new BorderLayout(0, 0));

	panelTags = new JPanel();
	FlowLayout flowLayout = (FlowLayout) panelTags.getLayout();
	flowLayout.setAlignment(FlowLayout.LEFT);
	add(panelTags, BorderLayout.CENTER);

	panelAdds = new JPanel();
	add(panelAdds, BorderLayout.EAST);
	panelAdds.setLayout(new BorderLayout(0, 0));

	btnAdd = new JButton();
	
	AbstractAction action = new AbstractAction("+") {
		private static final long serialVersionUID = 1L;
		@Override
		public void actionPerformed(ActionEvent ae) {
			JTextField field = new JTextField(10);
			panelTags.add(field);
			field.requestFocus();
			panelTags.revalidate();
			btnAdd.setEnabled(false);
			field.addActionListener(e -> {
				String s = field.getText();
				panelTags.remove(field);
				if (!s.equals(""))
					addTag(s);

				btnAdd.setEnabled(true);
				btnAdd.requestFocus();
			});

		}
	};

	btnAdd.setAction(action);

	btnAdd.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "ADD");
	btnAdd.getActionMap().put("ADD", action);
	panelAdds.add(btnAdd);
	componentFont = MTGControler.getInstance().getFont().deriveFont(Font.PLAIN, 15);

}
 
Example 19
Source File: ToolbarSimulationAction.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
public Component getToolbarPresenter() {
   tb = new JPanel();
   tb.setLayout(new FlowLayout());
   tb.setPreferredSize(new Dimension(230, 50));
   tb.setMaximumSize(new Dimension(230, 50));
   //tb.setFloatable(true);
   //tb.setBorder(BorderFactory.createTitledBorder(null, "Simulate", TitledBorder.CENTER, TitledBorder.TOP));
   tb.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
   JPopupMenu popup = new JPopupMenu();
   JMenuItem endTimeMenuitem = new JMenuItem("End time...");
   popup.add(endTimeMenuitem);
   //tb.addSeparator(new Dimension(10,40));
     try {
         JLabel jLabel1 = new JLabel("Simulate");
         jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
         tb.add(jLabel1);
         ImageIcon icon = new ImageIcon(getClass().getResource("/org/opensim/tracking/tools/run.png"));
         JButton dropdownButton = DropDownButtonFactory.createDropDownButton(icon, popup);
         dropdownButton.setPreferredSize(new Dimension(60,32));
         tb.add(Box.createHorizontalStrut(2));
         final ToolbarRunForwardAction runFD = (ToolbarRunForwardAction) ToolbarRunForwardAction.findObject((Class)Class.forName("org.opensim.tracking.tools.ToolbarRunForwardAction"), true);
         //JButton fdButton = new JButton(runFD);
         endTimeMenuitem.addActionListener(new ActionListener(){

         public void actionPerformed(ActionEvent ae) {
             SpecifyFinalTimeJPanel endTimePanel = new SpecifyFinalTimeJPanel(runFD.getFinalTime());
             DialogDescriptor dlg = new DialogDescriptor(endTimePanel,"Specify end time");
             dlg.setModal(true);
             DialogDisplayer.getDefault().createDialog(dlg).setVisible(true);
             Object userInput = dlg.getValue();
             if (((Integer)userInput).compareTo((Integer)DialogDescriptor.OK_OPTION)==0){
                 runFD.setFinalTime( endTimePanel.getEndtime());
             }
         }
     });

   tb.add(dropdownButton);
         dropdownButton.setAction(runFD);
         dropdownButton.setText("Run");
         tb.add(Box.createHorizontalStrut(5));
         ToolbarStopForwardAction stopFD = (ToolbarStopForwardAction) ToolbarStopForwardAction.findObject((Class)Class.forName("org.opensim.tracking.tools.ToolbarStopForwardAction"), true);
         JButton stopBtn = new JButton(stopFD);
         stopBtn.setPreferredSize(new Dimension(60,32));
         tb.add(stopBtn);
         tb.add(Box.createHorizontalStrut(3));
         //tb.add(new JLabel("simulate "+SimulationDB.getSimulationTime()+" sec."));
     } catch (ClassNotFoundException ex) {
         Exceptions.printStackTrace(ex);
     }
   //tb.addSeparator(new Dimension(10,40));
   return tb;
}
 
Example 20
Source File: HistoryColorChooserPanel.java    From nextreports-designer with Apache License 2.0 4 votes vote down vote up
private void activateButton(JButton button) {
  	button.setEnabled(true);
button.setAction(setColorAction);
Color color = button.getBackground();
button.setToolTipText(color.getRed() + "," + color.getGreen() + "," + color.getBlue());
  }