Java Code Examples for javax.swing.JButton#addActionListener()
The following examples show how to use
javax.swing.JButton#addActionListener() .
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: ErrorDisplay.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
private void _init_(String title, String s) { this.setBounds(100, 100, 400, 600); this.setTitle(title); JPanel contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(5, 5)); JPanel pageEnd = new JPanel(); pageEnd.setLayout(new GridLayout(1, 6, 10, 10)); contentPane.add(pageEnd, BorderLayout.PAGE_END); for (int i = 0; i < 4; i++) { pageEnd.add(new JPanel()); } JButton close = new JButton(JByteMod.res != null ? JByteMod.res.getResource("close") : "Close"); //res may not be loaded pageEnd.add(close); close.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ErrorDisplay.this.dispose(); } }); String st = s + suffix; contentPane.add(new JScrollPane(new JTextArea(st)), BorderLayout.CENTER); this.add(contentPane); this.setVisible(true); }
Example 2
Source File: Calculator.java From testing-cin with MIT License | 6 votes |
public JPanel buildClearPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 3)); JButton clear = new JButton("C"); clear.addActionListener(clearListener); panel.add(clear); JButton CEntry = new JButton("CE"); CEntry.addActionListener(clearListener); panel.add(CEntry); panel.add(buildOperatorButton("=", Operator.EQUALS)); return panel; }
Example 3
Source File: ConfigWindow.java From rscplus with GNU General Public License v3.0 | 6 votes |
/** * Adds a new keybind to the GUI and settings and registers it to be checked when keypresses are * sent to the applet. * * @param panel Panel to add the keybind label and button to * @param labelText Text describing the keybind's function as shown to the user on the config * window. * @param commandID Unique String matching an entry in the processKeybindCommand switch statement. * @param defaultModifier Default modifier value. This can be one of the enum values of * KeybindSet.KeyModifier, eg KeyModifier.CTRL * @param defaultKeyValue Default key value. This should match up with a KeyEvent.VK_ value. Set * to -1 to set the default as NONE */ private void addKeybindSet( JPanel panel, String labelText, String commandID, KeyModifier defaultModifier, int defaultKeyValue) { addKeybindLabel(panel, labelText); String buttonText = defaultModifier.toString() + " + " + KeyEvent.getKeyText(defaultKeyValue); if (defaultKeyValue == -1) buttonText = "NONE"; JButton b = addKeybindButton(panel, buttonText); KeybindSet kbs = new KeybindSet(b, commandID, defaultModifier, defaultKeyValue); KeyboardHandler.keybindSetList.add(kbs); setKeybindButtonText( kbs); // Set the text of the keybind button now that it has been initialized properly b.addActionListener(this.clickListener); b.addKeyListener(this.rebindListener); b.addFocusListener(focusListener); b.setFocusable(false); // Default KeybindSet KeyboardHandler.defaultKeybindSetList.put( commandID, new KeybindSet(null, commandID, defaultModifier, defaultKeyValue)); }
Example 4
Source File: MainMenuJPanel.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 6 votes |
private void jPanel_srEquipmentBrowseCategoriesComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jPanel_srEquipmentBrowseCategoriesComponentShown if (!initializedEquipmentBrowse) { List<String> categories = mil2525CSymbolController.getCategories(); for (final String category : categories) { final JButton button = new JButton(category); button.setFont(BUTTON_FONT); button.setHorizontalAlignment(SwingConstants.LEFT); button.setFocusable(false); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectedCategory = category; equipmentListJPanel_srEquipmentCategoryResults.removeAll(); jLabel_srEquipmentCategory.setText(selectedCategory); showCard("Spot Report Equipment Category Card"); } }); button.setMaximumSize(new Dimension(Integer.MAX_VALUE, 60)); button.setMinimumSize(new Dimension(0, 60)); jPanel_srEquipmentCategories.add(button); } initializedEquipmentBrowse = true; } }
Example 5
Source File: StatsContentPanel.java From magarena with GNU General Public License v3.0 | 6 votes |
public ActionPanel() { setOpaque(false); setLayout(new MigLayout("insets 0")); runButton = new JButton("Run test game..."); runButton.addActionListener(new AbstractAction("Run test game...") { @Override public void actionPerformed(ActionEvent e) { runButton.setEnabled(false); runButton.setText("Running test games: " + gamesSpinner.getValue()); doRunTestGame((int)gamesSpinner.getValue()); } }); gamesSpinner.setValue(10); MFileLink dbLink = new MFileLink(); dbLink.setFile(new File(H2Database.getDatabaseFile() + ".mv.db")); add(runButton, "w 200!"); add(gamesSpinner, "w 60!"); add(dbLink.component(), "w 100%"); }
Example 6
Source File: Test4759934.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void show(Window window, String command) { JButton button = new JButton(command); button.setActionCommand(command); button.addActionListener(this); button.setFont(button.getFont().deriveFont(64.0f)); window.add(button); window.pack(); window.setVisible(true); }
Example 7
Source File: RSSFeed.java From netbeans with Apache License 2.0 | 5 votes |
private JComponent buildProxyPanel() { Component header = getContentHeader(); JPanel panel = new JPanel(new GridBagLayout()); panel.setOpaque( false ); int row = 0; if( null != header ) { panel.add( header, new GridBagConstraints(0,row++,1,1,1.0,0.0, GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0 ) ); } panel.add( new JLabel(BundleSupport.getLabel("ErrCannotConnect")), // NOI18N new GridBagConstraints(0,row++,1,1,0.0,0.0, GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(5,10,10,5),0,0 ) ); if( showProxyButton ) { JButton button = new JButton(); Mnemonics.setLocalizedText( button, BundleSupport.getLabel( "ProxyConfig" ) ); // NOI18N button.setOpaque( false ); button.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { HttpProxySettings.getDefault().showConfigurationDialog(); } }); panel.add( button, new GridBagConstraints(0,row++,1,1,0.0,0.0, GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(5,10,10,5),0,0 ) ); } return panel; }
Example 8
Source File: PrintLatinCJKTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void showFrame() { JFrame f = new JFrame(); JTextArea jta = new JTextArea(info, 4, 30); jta.setLineWrap(true); jta.setWrapStyleWord(true); f.add("Center", jta); JButton b = new JButton("Print"); b.addActionListener(testInstance); f.add("South", b); f.pack(); f.setVisible(true); }
Example 9
Source File: ObserverTest2.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
public ObserverTest2() { setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); gbc = new GridBagConstraints(); gbc.weightx=1; //gbc.gridx =0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.insets.top =5; gbc.insets.left =5; gbc.insets.right =5; gbc.insets.bottom=5; ObservableModel mod = new ObservableModel(); ObservingField obs = new ObservingField(mod); add(obs,gbc); mod.setState(true); mod.setState(false); JButton thirdParty = new JButton("3rd party"); thirdParty.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { mod.setState(!mod.isState()); } }); add(thirdParty,gbc); }
Example 10
Source File: CatalogAction.java From netbeans with Apache License 2.0 | 5 votes |
public @Override void actionPerformed(ActionEvent e) { Dialog dialog = dialogWRef.get (); if (dialog == null || ! dialog.isShowing ()) { final CatalogPanel cp = new CatalogPanel (); JButton closeButton = new JButton (); Mnemonics.setLocalizedText (closeButton,NbBundle.getMessage (CatalogAction.class, "BTN_CatalogPanel_CloseButton")); // NOI18N JButton openInEditor = new JButton (); openInEditor.setEnabled (false); OpenInEditorListener l = new OpenInEditorListener (cp, openInEditor); openInEditor.addActionListener (l); cp.getExplorerManager ().addPropertyChangeListener (l); Mnemonics.setLocalizedText (openInEditor,NbBundle.getMessage (CatalogAction.class, "BTN_CatalogPanel_OpenInEditorButton")); // NOI18N DialogDescriptor dd = new DialogDescriptor (cp,NbBundle.getMessage (CatalogAction.class, "LBL_CatalogPanel_Title"), // NOI18N false, // modal new Object [] { openInEditor, closeButton }, closeButton, DialogDescriptor.DEFAULT_ALIGN, null, null); dd.setClosingOptions (null); // set helpctx to null again, DialogDescriptor replaces null with HelpCtx.DEFAULT_HELP dd.setHelpCtx (null); dialog = DialogDisplayer.getDefault ().createDialog (dd); dialog.setVisible (true); dialogWRef = new WeakReference<Dialog> (dialog); } else { dialog.toFront (); } }
Example 11
Source File: RadialGradientPrintingTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void createUI() { f = new JFrame("RadialGradient Printing Test"); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); final RadialGradientPrintingTest gpt = new RadialGradientPrintingTest(); Container c = f.getContentPane(); c.add(BorderLayout.CENTER, gpt); final JButton print = new JButton("Print"); print.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(gpt); final boolean doPrint = job.printDialog(); if (doPrint) { try { job.print(); } catch (PrinterException ex) { throw new RuntimeException(ex); } } } }); c.add(print, BorderLayout.SOUTH); f.pack(); f.setVisible(true); }
Example 12
Source File: PrintLatinCJKTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static void showFrame() { JFrame f = new JFrame(); JTextArea jta = new JTextArea(info, 4, 30); jta.setLineWrap(true); jta.setWrapStyleWord(true); f.add("Center", jta); JButton b = new JButton("Print"); b.addActionListener(testInstance); f.add("South", b); f.pack(); f.setVisible(true); }
Example 13
Source File: DetailsDisplay.java From GpsPrune with GNU General Public License v2.0 | 5 votes |
/** * Create a little button for rotating the current photo * @param inIcon icon to use (from IconManager) * @param inFunction function to call (from FunctionLibrary) * @return button object */ private static JButton makeRotateButton(String inIcon, GenericFunction inFunction) { JButton button = new JButton(IconManager.getImageIcon(inIcon)); button.setToolTipText(I18nManager.getText(inFunction.getNameKey())); button.setMargin(new Insets(0, 2, 0, 2)); button.addActionListener(new FunctionLauncher(inFunction)); return button; }
Example 14
Source File: JAccessSelectorPanel.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
public JAccessSelectorPanel(int accezz) { this.setLayout(new GridLayout(1, 4)); this.add(visibility = new VisibilityButton(accezz)); this.add(extras = new ExtrasButton(accezz)); this.add(other = new OtherButton(accezz)); accessHelper = new JButton( new ImageIcon(Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/resources/toolbar/table.png")))); accessHelper.addActionListener(e -> { new JAccessHelper(getAccess(), ae -> { setAccess(Integer.parseInt(ae.getActionCommand())); }).setVisible(true); }); this.add(accessHelper); }
Example 15
Source File: InputDialog.java From dkpro-jwpl with Apache License 2.0 | 5 votes |
/** * Creates the path input components. */ private void createPathSettings() { pathLabel = new JLabel("Please enter the path: "); pathLabel.setBounds(10, 10, 150, 25); this.add(pathLabel); pathField = new JTextField(); pathField.setBounds(10, 40, 250, 25); this.add(pathField); searchButton = new JButton("Search"); searchButton.setBounds(180, 10, 80, 25); searchButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { JFileChooser fc = new JFileChooser(); if (fc.showOpenDialog(new JPanel()) == JFileChooser.APPROVE_OPTION) { pathField.setText(fc.getSelectedFile().getPath()); } } }); this.add(searchButton); }
Example 16
Source File: RemoteTopologyPanel.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private static JButton buildButton(String resourceImagePath, ActionListener buttonListener, Dimension buttonSize) { ImageIcon icon = UIUtils.loadImageIcon(resourceImagePath); JButton button = new JButton(icon); button.setFocusable(false); button.addActionListener(buttonListener); button.setPreferredSize(buttonSize); button.setMinimumSize(buttonSize); button.setMaximumSize(buttonSize); return button; }
Example 17
Source File: GUIUtils.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
/** * Add a new button to a JPanel and then add the panel to a given component * * @param component Component to add the button to * @param text Button's text or null * @param icon Button's icon or null * @param listener Button's ActionListener or null * @param actionCommand Button's action command or null * @return Created button */ public static JButton addButtonInPanel(Container component, String text, ActionListener listener, String actionCommand) { JPanel panel = new JPanel(); JButton button = new JButton(text); if (listener != null) button.addActionListener(listener); if (actionCommand != null) button.setActionCommand(actionCommand); panel.add(button); if (component != null) component.add(panel); return button; }
Example 18
Source File: Test6179222.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
private static void test(ActionListener listener) { JButton button = new JButton("hi"); button.addActionListener(listener); button.doClick(); }
Example 19
Source File: ActionChooserScreen.java From chipster with MIT License | 4 votes |
public ActionChooserScreen(ImportSession importSession) { SwingClientApplication.setPlastic3DLookAndFeel(dialog); dialog.setPreferredSize(new Dimension(640, 480)); dialog.setLocationByPlatform(true); this.importSession = importSession; table = this.getTable(); JScrollPane scroll = new JScrollPane(table); // upper panel JLabel titleLabel = new JLabel("<html><p style=" + VisualConstants.HTML_DIALOG_TITLE_STYLE + ">" + TITLE_TEXT + "</p></html>", JLabel.LEFT); JLabel descriptionLabel = new JLabel("<html><p>" + INFO_TEXT + "</p></html>", JLabel.LEFT); GridBagConstraints c = new GridBagConstraints(); JPanel upperPanel = new JPanel(new GridBagLayout()); c.weightx = 1.0; c.weighty = 1.0; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.NORTHWEST; c.insets.set(10, 10, 5, 10); c.gridx = 0; c.gridy = 0; upperPanel.add(titleLabel, c); c.gridy++; upperPanel.add(descriptionLabel, c); // lower panel JPanel buttonPanel = new JPanel(); okButton = new JButton(" OK "); cancelButton = new JButton("Cancel"); copyButton = new JButton("Apply first action to all"); okButton.addActionListener(this); cancelButton.addActionListener(this); copyButton.addActionListener(this); JLabel sameSettingsLabel = new JLabel("<html><p>" + "When using Import tool to import more than one files, only define the contents of the first file and then apply the same settings for the rest of the files." + "</p></html>", JLabel.LEFT); sameSettingsLabel.setVerticalTextPosition(JLabel.TOP); //sameSettingsLabel.setPreferredSize(new Dimension(550, 40)); sameSettingsCheckBox = new JCheckBox("Define file structure once and apply the same settings to all files"); sameSettingsCheckBox.setEnabled(true); sameSettingsCheckBox.setSelected(true); sameSettingsCheckBox.setPreferredSize(new Dimension(550, 40)); buttonPanel.setLayout(new GridBagLayout()); GridBagConstraints g = new GridBagConstraints(); g.anchor = GridBagConstraints.NORTHWEST; g.gridx = 0; g.gridy = 0; g.weightx = 0.0; g.insets = new Insets(5, 5, 10, 5); buttonPanel.add(copyButton, g); g.gridy++; buttonPanel.add(sameSettingsCheckBox, g); g.insets = new Insets(5, 0, 10, 5); g.gridy++; g.anchor = GridBagConstraints.EAST; buttonPanel.add(cancelButton, g); g.gridx++; buttonPanel.add(okButton, g); dialog.setLayout(new BorderLayout()); dialog.add(upperPanel, BorderLayout.NORTH); dialog.add(scroll, BorderLayout.CENTER); dialog.add(buttonPanel, BorderLayout.SOUTH); dialog.pack(); dialog.pack(); okButton.requestFocusInWindow(); dialog.setVisible(true); }
Example 20
Source File: IPCamAddDialog.java From MtgDesktopCompanion with GNU General Public License v3.0 | 4 votes |
public IPCamAddDialog() { GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{0, 0, 0}; gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0}; gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; getContentPane().setLayout(gridBagLayout); getContentPane().add(new JLabel("Camera Name :"), UITools.createGridBagConstraints(null, null, 0, 1)); getContentPane().add(new JLabel("Camera URI : "), UITools.createGridBagConstraints(null, null, 0, 2)); getContentPane().add(new JLabel("Camera Mode :"), UITools.createGridBagConstraints(null, null, 0, 3)); txtName = new JTextField(10); getContentPane().add(txtName, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 1, 1)); txtUrl = new JTextField(10); getContentPane().add(txtUrl, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 1, 2)); comboBox = UITools.createCombobox(IpCamMode.values()); getContentPane().add(comboBox, UITools.createGridBagConstraints(null, GridBagConstraints.HORIZONTAL, 1, 3)); JButton btnAdd = new JButton(MTGConstants.ICON_CHECK); JButton btnCancel = new JButton(MTGConstants.ICON_DELETE); JPanel panel = new JPanel(); panel.add(btnAdd); panel.add(btnCancel); getContentPane().add(panel, UITools.createGridBagConstraints(null, GridBagConstraints.BOTH, 1, 4)); setLocationRelativeTo(null); pack(); btnAdd.addActionListener(al->{ if(!txtName.getText().isEmpty() && !txtUrl.getText().isEmpty()) { WebcamUtils.inst().registerIPCam(txtName.getText(),txtUrl.getText(),(IpCamMode)comboBox.getSelectedItem()); hasNew=true; dispose(); } }); btnCancel.addActionListener(al->dispose()); }