Java Swing Action Event Button Example
Best Java code snippets using javax.swing.JButton.addActionListener (Showing top 20 results out of 11,232)
Refine search
private void buildExtractButton() { if (extractButton == null) { JPanel buttonPanel = new JPanel (); extractButton = new JButton ( "Extract" ); buttonPanel. add (extractButton); frame.add(buttonPanel, BorderLayout.SOUTH); extractButton. addActionListener (actor); } }
JLabel label = new JLabel (); JButton button = new JButton ( "Click me" ); button. addActionListener ((ActionEvent e) -> { label.setText( "Button was clicked" ); });
private JButton createNewRowButton() { final JButton newRowButton = new JButton (); newRowButton.setText( "+" ); newRowButton. addActionListener (e -> rootPanel. add (createArtifactRow( "" , "" , "" , "" ))); return newRowButton; }
private void buildExtractButton() { if (extractButton == null) { JPanel buttonPanel = new JPanel (); extractButton = new JButton ( "Run NER" ); buttonPanel. add (extractButton); frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH); extractButton. addActionListener (actor); } }
public ProgressPanel( final MainWindow mainWindow, boolean showCancelButton) { progressLabel = new JLabel (); progressBar = new JProgressBar( 0 , 100 ); progressBar.setIndeterminate( true ); progressBar.setStringPainted( false ); progressLabel.setLabelFor(progressBar); setBorder(BorderFactory.createEmptyBorder( 2 , 2 , 2 , 2 )); setLayout( new BoxLayout( this , BoxLayout.X_AXIS)); setVisible( false ); add(progressLabel); add(progressBar); if (showCancelButton) { JButton cancelButton = new JButton (ICON_CANCEL); cancelButton.setPreferredSize( new Dimension(ICON_CANCEL.getIconWidth(), ICON_CANCEL.getIconHeight())); cancelButton.setToolTipText( "Cancel background jobs" ); cancelButton.setBorderPainted( false ); cancelButton.setFocusPainted( false ); cancelButton.setContentAreaFilled( false ); cancelButton. addActionListener ( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { mainWindow.cancelBackgroundJobs(); } }); add(cancelButton); } }
tabPane.addTab(title, tabBody); int index = tabPane.indexOfTab(title); JPanel pnlTab = new JPanel( new GridBagLayout()); pnlTab.setOpaque( false ); JLabel lblTitle = new JLabel(title); JButton btnClose = new JButton ( "x" ); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0 ; gbc.gridy = 0 ; gbc.weightx = 1 ; pnlTab. add (lblTitle, gbc); gbc.gridx++; gbc.weightx = 0 ; pnlTab. add (btnClose, gbc); tabPane.setTabComponentAt(index, pnlTab); btnClose. addActionListener (myCloseActionHandler);
private JButton createButton(String text) { JButton retval= new JButton (text); retval. addActionListener ( this ); return retval; }
private JComponent getSouthLabel() { final JPanel result = new JPanel (); final JButton ok = new JButton ( "OK" ); ok. addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent ae) { dispose(); } }); result. add (ok); return result; }
private HitRateMetricsSandbox() { IgniteUtils.onGridStart(); JButton hitBtn = new JButton ( "Hit" ); hitBtn. addActionListener ( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { metrics.onHit(); } }); new Timer( 100 , new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { rateLb.setText(Double.toString(metrics.getRate())); } }).start(); setContentPane(createPanel( new JLabel ( "Hits in 5 seconds:" ), rateLb, hitBtn)); setMinimumSize( new Dimension( 300 , 120 )); }
contentPanel. add (chart, new GridBagConstraints( 0 , 0 , 1 , 1 , 0 , 0 , GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets( 0 , 0 , 0 , 0 ), 0 , 0 )); expandButton = new JButton ( "+" ); expandButton.setBorder(BorderFactory.createEmptyBorder( 4 , 10 , 4 , 10 )); contentPanel. add (expandButton, new GridBagConstraints( 1 , 0 , 1 , 1 , 1 , 0 , GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets( 0 , 6 , 0 , 0 ), 0 , 0 )); expandButton. addActionListener ( new ActionListener() { public void actionPerformed (ActionEvent event) { chart.setExpanded(!chart.isExpanded());
private JButton createRemoveRowButton( final JPanel panel) { final JButton removeRowButton = new JButton (); removeRowButton.setText( "-" ); removeRowButton. addActionListener (e -> { final int idx = getComponentIndex(panel); rootPanel.remove(panel); rows.remove(idx); }); return removeRowButton; }
private JPanel makeTSurgeonButtons() { JPanel tsurgeonButtonBox = new JPanel (); tsurgeonButtonBox.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); tsurgeonButtonBox. setLayout ( new GridBagLayout()); tsurgeonHelp = new JButton ( "Help" ); tsurgeonHelp. addActionListener ( this ); cancelTsurgeon = new JButton ( "Cancel" ); cancelTsurgeon. addActionListener ( this ); runScript = new JButton ( "Run script" ); runScript. addActionListener ( this ); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.NORTHEAST; c.fill = GridBagConstraints.HORIZONTAL; tsurgeonButtonBox. add (runScript,c); tsurgeonButtonBox. add (cancelTsurgeon,c); tsurgeonButtonBox. add (tsurgeonHelp,c); c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0 ; c.weighty = 1.0 ; tsurgeonButtonBox. add ( new JLabel (), c); return tsurgeonButtonBox; }
JButton cancel = new javax.swing.JButton (); new JLabel ( "Parsing " + sentences.size() + " sentences" )); dialog.add(BorderLayout.CENTER, progress); dialog.add(BorderLayout.SOUTH, cancel); cancel. addActionListener (evt -> thread.cancelled = true );
contentPanel. add (chart, new GridBagConstraints( 0 , 0 , 1 , 1 , 0 , 0 , GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets( 0 , 0 , 0 , 0 ), 0 , 0 )); expandButton = new JButton ( "+" ); expandButton.setBorder(BorderFactory.createEmptyBorder( 4 , 10 , 4 , 10 )); contentPanel. add (expandButton, new GridBagConstraints( 1 , 0 , 1 , 1 , 1 , 0 , GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets( 0 , 6 , 0 , 0 ), 0 , 0 )); expandButton. addActionListener ( new ActionListener() { public void actionPerformed (ActionEvent event) { chart.setExpanded(!chart.isExpanded());
private JPanel makeFoundStatsBox() { JPanel foundStatsBox = new JPanel (); foundStatsBox. setLayout ( new GridBagLayout()); Box labelBox = Box.createHorizontalBox(); foundStats = new JLabel ( " " ); labelBox.add(foundStats); historyButton = new JButton ( "Statistics" ); historyButton.setEnabled( false ); historyButton. addActionListener ( this ); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.weightx = 1.7 ; foundStatsBox. add (labelBox,c); c.weightx = . 3 ; c.gridwidth = 1 ; foundStatsBox. add (historyButton); return foundStatsBox; }
public SearchBar(RSyntaxTextArea textArea) { rTextArea = textArea; JLabel findLabel = new JLabel (NLS.str( "search.find" ) + ":" ); add(findLabel); add(searchField); JButton prevButton = new JButton (NLS.str( "search.previous" )); prevButton.setIcon(ICON_UP); prevButton. addActionListener ( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { add(prevButton); JButton nextButton = new JButton (NLS.str( "search.next" )); nextButton.setIcon(ICON_DOWN); nextButton. addActionListener ( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { add(wholeWordCB); JButton closeButton = new JButton (); closeButton.setIcon(ICON_CLOSE); closeButton. addActionListener (l -> toggle()); closeButton.setBorderPainted( false ); add(closeButton);
FileBrowser() { super (); setLayout( new FlowLayout(FlowLayout.LEFT, 0 , 0 )); textField = new JTextField( 15 ); textField.setEnabled( false ); add(textField); browse = new JButton ( "Browse" ); add(browse); browse. addActionListener (e -> { JFileChooser jFileChooser = new JFileChooser(file != null ? file.getParentFile() : null); int returnVal = jFileChooser.showOpenDialog(FileBrowser. this ); if (returnVal == JFileChooser.APPROVE_OPTION) { setFile(jFileChooser.getSelectedFile()); } }); }
private JPanel makeBrowseButtonBox() { JPanel buttonBox = new JPanel (); buttonBox.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); buttonBox. setLayout ( new GridBagLayout()); browseButton = new JButton ( "Browse Trees" ); browseButton. addActionListener ( this ); JLabel sizeLabel = new JLabel ( "Tree size:" ); JSlider fontSlider = new JSlider( 2 , 64 , 12 ); fontSlider.addChangeListener( this ); GridBagConstraints buttonConstraints = new GridBagConstraints(); buttonConstraints.fill = GridBagConstraints.HORIZONTAL; buttonConstraints.weightx = 0.2 ; buttonConstraints.weighty = 0.2 ; buttonBox. add (browseButton,buttonConstraints); buttonConstraints.weightx = 0.6 ; buttonBox. add (fontSlider, buttonConstraints); buttonConstraints.weightx = 0.2 ; buttonBox. add (sizeLabel, buttonConstraints); return buttonBox; }
Source: https://www.tabnine.com/code/java/methods/javax.swing.JButton/addActionListener
0 Response to "Java Swing Action Event Button Example"
Post a Comment