Java Code Examples for javax.swing.JButton#setDefaultCapable()
The following examples show how to use
javax.swing.JButton#setDefaultCapable() .
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: VariablesPanel.java From netbeans with Apache License 2.0 | 6 votes |
private Variable showDialog() { JPanel inset = new JPanel(new BorderLayout()); inset.setBorder(new EmptyBorder(12,12,0,12)); inset.add(this); inset.getAccessibleContext().setAccessibleName(NbBundle.getMessage(VariablesPanel.class, "AN_Manage_Variables")); inset.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(VariablesPanel.class, "AD_Manage_Variables")); DialogDescriptor dd = new DialogDescriptor(inset, NbBundle.getMessage(VariablesPanel.class, "TITLE_Manage_Variables")); // NOI18N dd.setModal(true); final JButton ok = new JButton(NbBundle.getMessage(VariablesPanel.class, "BUTTON_OK")); // NOI18N ok.setDefaultCapable(true); explorer.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { removeButton.setEnabled(explorer.getSelectedNodes().length > 0); editButton.setEnabled(explorer.getSelectedNodes().length == 1); } }); dd.setOptions(new Object[] {ok, NotifyDescriptor.CANCEL_OPTION}); dd.setClosingOptions(new Object[] {ok, NotifyDescriptor.CANCEL_OPTION}); if (DialogDisplayer.getDefault().notify(dd) == ok) { model.save(); if (explorer.getSelectedNodes().length == 1) { return explorer.getSelectedNodes()[0].getLookup().lookup(Variable.class); } } return null; }
Example 2
Source File: CommonDialog.java From javamoney-examples with Apache License 2.0 | 6 votes |
private JButton createButton(String text, String defaultText, ActionListener listener, CommonIconKeys key, String command, boolean defaultEnabled) { JButton button = new JButton(); if(defaultEnabled == true) { button.setDefaultCapable(true); getRootPane().setDefaultButton(button); } if(text.length() == 0) { text = defaultText; } buildButton(button, text, key.getIcon(), listener, command, null); return button; }
Example 3
Source File: NumericInputDialog.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
private JPanel createButtonPanel() { final JButton btnCancel = new JButton( getCancelAction() ); final JButton btnConfirm = new JButton( getConfirmAction() ); final JPanel buttonPanel = new JPanel(); buttonPanel.setLayout( new GridLayout( 1, 2, 5, 5 ) ); buttonPanel.add( btnConfirm ); buttonPanel.add( btnCancel ); btnConfirm.setDefaultCapable( true ); getRootPane().setDefaultButton( btnConfirm ); buttonPanel.registerKeyboardAction( getConfirmAction(), KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); final JPanel buttonCarrier = new JPanel(); buttonCarrier.setLayout( new FlowLayout( FlowLayout.RIGHT ) ); buttonCarrier.add( buttonPanel ); return buttonCarrier; }
Example 4
Source File: AbstractExportDialog.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
protected JPanel createButtonPanel() { final JButton btnCancel = new JButton( getCancelAction() ); final JButton btnConfirm = new JButton( getConfirmAction() ); final JPanel buttonPanel = new JPanel(); buttonPanel.setLayout( new GridLayout( 1, 2, 5, 5 ) ); buttonPanel.add( btnConfirm ); buttonPanel.add( btnCancel ); btnConfirm.setDefaultCapable( true ); getRootPane().setDefaultButton( btnConfirm ); buttonPanel.registerKeyboardAction( getConfirmAction(), KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); final JPanel buttonCarrier = new JPanel(); buttonCarrier.setLayout( new FlowLayout( FlowLayout.RIGHT ) ); buttonCarrier.add( buttonPanel ); return buttonCarrier; }
Example 5
Source File: SnippetNavigator.java From beautyeye with Apache License 2.0 | 6 votes |
public SnippetNavigator(SnippetMap snippetMap) { this.snippetMap = snippetMap; snippetMap.addPropertyChangeListener(new SnippetHighlightListener()); setLayout(null); NO_SNIPPET = getString("CodeViewer.snippets.noCodeHighlighted", "No Code highlight selected"); statusLabel = new JLabel(NO_SNIPPET); statusLabel.setHorizontalAlignment(JLabel.CENTER); add(statusLabel); prevButton = (JButton) add(new NavButton()); prevButton.setDefaultCapable(false); prevButton.setVisible(false); nextButton = (JButton) add(new NavButton()); nextButton.setDefaultCapable(false); nextButton.setVisible(false); applyDefaults(); }
Example 6
Source File: SnippetNavigator.java From littleluck with Apache License 2.0 | 6 votes |
public SnippetNavigator(SnippetMap snippetMap) { this.snippetMap = snippetMap; snippetMap.addPropertyChangeListener(new SnippetHighlightListener()); setLayout(null); NO_SNIPPET = getString("CodeViewer.snippets.noCodeHighlighted", "No Code highlight selected"); statusLabel = new JLabel(NO_SNIPPET); statusLabel.setHorizontalAlignment(JLabel.CENTER); add(statusLabel); prevButton = (JButton) add(new NavButton()); prevButton.setDefaultCapable(false); prevButton.setVisible(false); nextButton = (JButton) add(new NavButton()); nextButton.setDefaultCapable(false); nextButton.setVisible(false); applyDefaults(); }
Example 7
Source File: AttachDialog.java From visualvm with GNU General Public License v2.0 | 6 votes |
private static void showDetails(RunningVM vm) { HTMLTextArea area = new HTMLTextArea(); JScrollPane areaScroll = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); areaScroll.setBorder(BorderFactory.createEmptyBorder()); areaScroll.setViewportBorder(BorderFactory.createEmptyBorder()); areaScroll.setPreferredSize(new Dimension(500, 260)); configureScrollBar(areaScroll.getVerticalScrollBar()); configureScrollBar(areaScroll.getHorizontalScrollBar()); area.setText(getDetails(vm)); area.setCaretPosition(0); HelpCtx helpCtx = new HelpCtx("ProcessDetails.HelpCtx"); //NOI18N JButton close = new JButton(Bundle.AttachDialog_BtnClose()); close.setDefaultCapable(true); DialogDescriptor dd = new DialogDescriptor(areaScroll, Bundle.AttachDialog_DetailsCaption(getProcessName(vm.getMainClass())), true, new Object[] { close }, close, DialogDescriptor.DEFAULT_ALIGN, helpCtx, null); Dialog d = DialogDisplayer.getDefault().createDialog(dd); d.pack(); d.setVisible(true); }
Example 8
Source File: HiddenDefaultButtonTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void createGUI() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Default button"); button.setDefaultCapable(true); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ButtonClickCount++; } }); frame.add(button); button.setVisible(false); frame.getRootPane().setDefaultButton(button); frame.setSize(200, 200); frame.setLocationRelativeTo(null); frame.setVisible(true); }
Example 9
Source File: ConnectAction.java From netbeans with Apache License 2.0 | 6 votes |
public void actionPerformed (ActionEvent evt) { bOk = new JButton (NbBundle.getMessage (ConnectAction.class, "CTL_Ok")); // NOI18N bCancel = new JButton (NbBundle.getMessage (ConnectAction.class, "CTL_Cancel")); // NOI18N bOk.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage (ConnectAction.class, "ACSD_CTL_Ok")); // NOI18N bCancel.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage (ConnectAction.class, "ACSD_CTL_Cancel")); // NOI18N bCancel.setDefaultCapable(false); cp = new ConnectorPanel (); descr = new DialogDescriptor ( cp, NbBundle.getMessage (ConnectAction.class, "CTL_Connect_to_running_process"), true, // modal new ConnectListener (cp) ); descr.setOptions (new JButton[] { bOk, bCancel }); notificationSupport = descr.createNotificationLineSupport(); descr.setClosingOptions (new Object [0]); descr.setHelpCtx(HelpCtx.findHelp(cp)); // This is mandatory so that the descriptor tracks the changes in help correctly. dialog = DialogDisplayer.getDefault ().createDialog (descr); dialog.setVisible(true); }
Example 10
Source File: AttachDialog.java From netbeans with Apache License 2.0 | 6 votes |
private static void showDetails(RunningVM vm) { HTMLTextArea area = new HTMLTextArea(); JScrollPane areaScroll = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); areaScroll.setBorder(BorderFactory.createEmptyBorder()); areaScroll.setViewportBorder(BorderFactory.createEmptyBorder()); areaScroll.setPreferredSize(new Dimension(500, 260)); configureScrollBar(areaScroll.getVerticalScrollBar()); configureScrollBar(areaScroll.getHorizontalScrollBar()); area.setText(getDetails(vm)); area.setCaretPosition(0); HelpCtx helpCtx = new HelpCtx("ProcessDetails.HelpCtx"); //NOI18N JButton close = new JButton(Bundle.AttachDialog_BtnClose()); close.setDefaultCapable(true); DialogDescriptor dd = new DialogDescriptor(areaScroll, Bundle.AttachDialog_DetailsCaption(getProcessName(vm.getMainClass())), true, new Object[] { close }, close, DialogDescriptor.DEFAULT_ALIGN, helpCtx, null); Dialog d = DialogDisplayer.getDefault().createDialog(dd); d.pack(); d.setVisible(true); }
Example 11
Source File: ApisupportAntUIUtils.java From netbeans with Apache License 2.0 | 6 votes |
/** * Show an OK/cancel-type dialog with customized button texts. * Only a separate method because it is otherwise cumbersome to replace * the OK button with a button that is set as the default. * @param title the dialog title * @param message the body of the message (usually HTML text) * @param acceptButton a label for the default accept button; should not use mnemonics * @param accDescrAcceptButton a accessible description for acceptButton * @param cancelButton a label for the cancel button (or null for default); should not use mnemonics * @param messageType {@link NotifyDescriptor#WARNING_MESSAGE} or similar * @return true if user accepted the dialog */ public static boolean showAcceptCancelDialog(String title, String message, String acceptButton, String accDescrAcceptButton , String cancelButton, int messageType) { DialogDescriptor d = new DialogDescriptor(message, title); d.setModal(true); JButton accept = new JButton(acceptButton); accept.setDefaultCapable(true); if ( accDescrAcceptButton != null ){ accept.getAccessibleContext(). setAccessibleDescription( accDescrAcceptButton); } d.setOptions(new Object[] { accept, cancelButton != null ? new JButton(cancelButton) : NotifyDescriptor.CANCEL_OPTION, }); d.setMessageType(messageType); return DialogDisplayer.getDefault().notify(d).equals(accept); }
Example 12
Source File: AdvancedActionPanel.java From netbeans with Apache License 2.0 | 6 votes |
/** Displays dialog. */ public boolean display() { String title = NbBundle.getMessage(RunTargetsAction.class, "TITLE_run_advanced"); DialogDescriptor dd = new DialogDescriptor(this, title); dd.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION); JButton run = new JButton(NbBundle.getMessage(RunTargetsAction.class, "LBL_run_advanced_run")); run.setDefaultCapable(true); JButton cancel = new JButton(NbBundle.getMessage(RunTargetsAction.class, "LBL_run_advanced_cancel")); dd.setOptions(new Object[] {run, cancel}); dd.setModal(true); Object result = DialogDisplayer.getDefault().notify(dd); if (result.equals(run)) { try { run(); return true; } catch (IOException x) { AntModule.err.notify(x); } } return false; }
Example 13
Source File: RunTargetsAction.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(ActionEvent e) { String title = NbBundle.getMessage(RunTargetsAction.class, "TITLE_run_advanced"); AdvancedActionPanel panel = new AdvancedActionPanel(project, allTargets); DialogDescriptor dd = new DialogDescriptor(panel, title); dd.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION); JButton run = new JButton(NbBundle.getMessage(RunTargetsAction.class, "LBL_run_advanced_run")); run.setDefaultCapable(true); JButton cancel = new JButton(NbBundle.getMessage(RunTargetsAction.class, "LBL_run_advanced_cancel")); dd.setOptions(new Object[] {run, cancel}); dd.setModal(true); Object result = DialogDisplayer.getDefault().notify(dd); if (result.equals(run)) { try { panel.run(); } catch (IOException x) { AntModule.err.notify(x); } } }
Example 14
Source File: AppClientProjectProperties.java From netbeans with Apache License 2.0 | 5 votes |
private static boolean showModifiedMessage (String title) { String message = NbBundle.getMessage(AppClientProjectProperties.class,"TXT_Regenerate"); JButton regenerateButton = new JButton (NbBundle.getMessage(AppClientProjectProperties.class,"CTL_RegenerateButton")); regenerateButton.setDefaultCapable(true); regenerateButton.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(AppClientProjectProperties.class,"AD_RegenerateButton")); NotifyDescriptor d = new NotifyDescriptor.Message (message, NotifyDescriptor.WARNING_MESSAGE); d.setTitle(title); d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION); d.setOptions(new Object[] {regenerateButton, NotifyDescriptor.CANCEL_OPTION}); return DialogDisplayer.getDefault().notify(d) == regenerateButton; }
Example 15
Source File: JavaActions.java From netbeans with Apache License 2.0 | 5 votes |
/** * Display an alert asking the user whether to really generate a target. * @param commandDisplayName the display name of the action to be bound * @param scriptPath the path that to the script that will be generated or written to * @return true if IDE should proceed */ private boolean alert(String commandDisplayName, String scriptPath) { String projectDisplayName = ProjectUtils.getInformation(project).getDisplayName(); String title = NbBundle.getMessage(JavaActions.class, "TITLE_generate_target_dialog", commandDisplayName, projectDisplayName); String body = NbBundle.getMessage(JavaActions.class, "TEXT_generate_target_dialog", commandDisplayName, scriptPath); NotifyDescriptor d = new NotifyDescriptor.Message(body, NotifyDescriptor.QUESTION_MESSAGE); d.setTitle(title); d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION); JButton generate = new JButton(NbBundle.getMessage(JavaActions.class, "LBL_generate")); generate.setDefaultCapable(true); d.setOptions(new Object[] {generate, NotifyDescriptor.CANCEL_OPTION}); return DialogDisplayer.getDefault().notify(d) == generate; }
Example 16
Source File: WebFreeFormActionProvider.java From netbeans with Apache License 2.0 | 5 votes |
/** * Display an alert asking the user whether to really generate a target. * @param commandDisplayName the display name of the action to be bound * @param scriptPath the path that to the script that will be generated or written to * @return true if IDE should proceed */ private boolean alert(String commandDisplayName, String scriptPath) { String projectDisplayName = ProjectUtils.getInformation(project).getDisplayName(); String title = NbBundle.getMessage(WebFreeFormActionProvider.class, "TITLE_generate_target_dialog", commandDisplayName, projectDisplayName); String body = NbBundle.getMessage(WebFreeFormActionProvider.class, "TEXT_generate_target_dialog", commandDisplayName, scriptPath); NotifyDescriptor d = new NotifyDescriptor.Message(body, NotifyDescriptor.QUESTION_MESSAGE); d.setTitle(title); d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION); JButton generate = new JButton(NbBundle.getMessage(WebFreeFormActionProvider.class, "LBL_generate")); generate.setDefaultCapable(true); d.setOptions(new Object[] {generate, NotifyDescriptor.CANCEL_OPTION}); return DialogDisplayer.getDefault().notify(d) == generate; }
Example 17
Source File: PreviewParametersDialog.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private JPanel createButtonsPanel() { final JButton okButton = new JButton( confirmAction ); okButton.setDefaultCapable( true ); final JPanel buttonsPanel = new JPanel(); buttonsPanel.setLayout( new FlowLayout( FlowLayout.RIGHT, 5, 5 ) ); buttonsPanel.setBorder( BorderFactory.createMatteBorder( 1, 0, 0, 0, Color.LIGHT_GRAY ) ); buttonsPanel.add( okButton ); buttonsPanel.add( new JButton( new CancelAction() ) ); return buttonsPanel; }
Example 18
Source File: ArlosGitNotationPrompt.java From ApprovalTests.Java with Apache License 2.0 | 5 votes |
private void createQuickbutton(String label, String commitMessage, int shortcut, int position) { GridBagConstraints c = new GridBagConstraints(); JButton quick = new JButton(label); quick.setMnemonic(shortcut); quick.setDefaultCapable(true); c.insets = new Insets(10, 10, 10, 10); c.gridx = position; c.gridwidth = 1; c.gridy = 3; quick.addActionListener(e -> doCommit(commitMessage)); panel.add(quick, c); }
Example 19
Source File: NotifyExcPanel.java From netbeans with Apache License 2.0 | 4 votes |
/** Constructor. */ private NotifyExcPanel () { java.util.ResourceBundle bundle = org.openide.util.NbBundle.getBundle(NotifyExcPanel.class); next = new JButton (); Mnemonics.setLocalizedText(next, bundle.getString("CTL_NextException")); // bugfix 25684, don't set Previous/Next as default capable next.setDefaultCapable (false); previous = new JButton (); Mnemonics.setLocalizedText(previous, bundle.getString("CTL_PreviousException")); previous.setDefaultCapable (false); details = new JButton (); details.setDefaultCapable (false); output = new JTextPane() { public @Override boolean getScrollableTracksViewportWidth() { return false; } }; output.setEditable(false); Font f = output.getFont(); output.setFont(new Font("Monospaced", Font.PLAIN, null == f ? 12 : f.getSize() + 1)); // NOI18N output.setForeground(UIManager.getColor("Label.foreground")); // NOI18N output.setBackground(UIManager.getColor("Label.background")); // NOI18N setLayout( new BorderLayout() ); add(new JScrollPane(output)); setBorder( new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.LOWERED)); next.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_NextException")); previous.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_PreviousException")); output.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_ExceptionStackTrace")); output.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_ExceptionStackTrace")); getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_NotifyExceptionPanel")); descriptor = new DialogDescriptor ("", ""); // NOI18N descriptor.setMessageType (DialogDescriptor.ERROR_MESSAGE); descriptor.setOptions (computeOptions(previous, next)); descriptor.setAdditionalOptions (new Object[] { details }); descriptor.setClosingOptions (new Object[0]); descriptor.setButtonListener (this); // bugfix #27176, create dialog in modal state if some other modal // dialog is opened at the time // #53328 do not let the error dialog to be created modal unless the main // window is visible. otherwise the error message may be hidden behind // the main window thus making the main window unusable descriptor.setModal( isModalDialogPresent() && WindowManager.getDefault().getMainWindow().isVisible() ); setPreferredSize(new Dimension(SIZE_PREFERRED_WIDTH + extraW, SIZE_PREFERRED_HEIGHT + extraH)); dialog = DialogDisplayer.getDefault().createDialog(descriptor); if( null != lastBounds ) { lastBounds.width = Math.max( lastBounds.width, SIZE_PREFERRED_WIDTH+extraW ); dialog.setBounds( lastBounds ); } dialog.getAccessibleContext().setAccessibleName(bundle.getString("ACN_NotifyExcPanel_Dialog")); // NOI18N dialog.getAccessibleContext().setAccessibleDescription(bundle.getString("ACD_NotifyExcPanel_Dialog")); // NOI18N }
Example 20
Source File: PropertyDialogManager.java From netbeans with Apache License 2.0 | 4 votes |
/** Creates proper DialogDescriptor and obtain dialog instance * via DialogDisplayer.createDialog() call. */ private void createDialog(boolean isModal, String title, HelpCtx helpCtx) { if (component instanceof Window) { // custom component is already a window --> just return it // from getDialog dialog = (Window) component; dialog.pack(); return; } // prepare our options (buttons) boolean cannotWrite = false; boolean defaultValue = false; if (model instanceof ExPropertyModel) { FeatureDescriptor fd = ((ExPropertyModel) model).getFeatureDescriptor(); if (fd instanceof Node.Property) { prop = (Node.Property) fd; cannotWrite = !prop.canWrite(); defaultValue = PropUtils.shallBeRDVEnabled(prop); } } Object defaultOption; Object[] options; if ((editor == null) || (cannotWrite)) { JButton closeButton = new JButton(getString("CTL_Close")); closeButton.getAccessibleContext().setAccessibleDescription(getString("ACSD_CTL_Close")); options = new Object[] { closeButton }; defaultOption = closeButton; } else { okButton = new JButton(getString("CTL_OK")); okButton.getAccessibleContext().setAccessibleDescription(getString("ACSD_CTL_OK")); JButton cancelButton = new JButton(getString("CTL_Cancel")); cancelButton.setVerifyInputWhenFocusTarget(false); cancelButton.getAccessibleContext().setAccessibleDescription(getString("ACSD_CTL_Cancel")); cancelButton.setDefaultCapable(false); if (defaultValue) { JButton defaultButton = new JButton(); String name = getString("CTL_Default"); Mnemonics.setLocalizedText(defaultButton, name); defaultButton.setActionCommand(name); defaultButton.getAccessibleContext().setAccessibleDescription(getString("ACSD_CTL_Default")); defaultButton.setDefaultCapable(false); defaultButton.setVerifyInputWhenFocusTarget(false); if ("Aqua".equals(UIManager.getLookAndFeel().getID())) { //Support Aqua button ordering options = new Object[] { defaultButton, cancelButton, okButton }; } else { options = new Object[] { okButton, defaultButton, cancelButton }; } } else { if ("Aqua".equals(UIManager.getLookAndFeel().getID())) { options = new Object[] { cancelButton, okButton }; } else { options = new Object[] { okButton, cancelButton }; } } defaultOption = okButton; } if ((env != null) && (okButton != null)) { okButtonState = env.getState() != PropertyEnv.STATE_INVALID; if (okButton != null) { okButton.setEnabled(okButtonState); } } if (env != null) { envStateBeforeDisplay = env.getState(); } // create dialog descriptor, create & return the dialog // bugfix #24998, set helpCtx obtain from PropertyEnv.getFeatureDescriptor() DialogDescriptor descriptor = new DialogDescriptor(component, title, isModal, options, defaultOption, DialogDescriptor.DEFAULT_ALIGN, helpCtx, this); dialog = DialogDisplayer.getDefault().createDialog(descriptor); }