javax.swing.JButton.addActionListener()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(293)

本文整理了Java中javax.swing.JButton.addActionListener()方法的一些代码示例,展示了JButton.addActionListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JButton.addActionListener()方法的具体详情如下:
包路径:javax.swing.JButton
类名称:JButton
方法名:addActionListener

JButton.addActionListener介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

JButton button = new JButton("Do Something");
button.addActionListener( action );

代码示例来源:origin: stanfordnlp/CoreNLP

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);
 }
}

代码示例来源:origin: stackoverflow.com

JLabel label = new JLabel();
JButton button = new JButton("Click me");
button.addActionListener((ActionEvent e) -> {
  // This event listener is run when the button is clicked.
  // We don't need to loop while waiting.
  label.setText("Button was clicked");
});

代码示例来源:origin: ballerina-platform/ballerina-lang

private JButton createNewRowButton() {
  final JButton newRowButton = new JButton();
  newRowButton.setText("+");
  newRowButton.addActionListener(e -> rootPanel.add(createArtifactRow("", "", "", "")));
  return newRowButton;
}

代码示例来源:origin: stanfordnlp/CoreNLP

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);
 }
}

代码示例来源:origin: skylot/jadx

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);
  }
}

代码示例来源:origin: stackoverflow.com

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);

代码示例来源:origin: wildfly/wildfly

private JButton createButton(String text) {
  JButton retval=new JButton(text);
  retval.addActionListener(this);
  return retval;
}

代码示例来源:origin: plantuml/plantuml

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;
}

代码示例来源:origin: apache/ignite

/**
 * Default constructor.
 */
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));
}

代码示例来源:origin: libgdx/libgdx

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());

代码示例来源:origin: ballerina-platform/ballerina-lang

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;
}

代码示例来源:origin: stanfordnlp/CoreNLP

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);
 //make constraints and add in
 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;
}
//separated out to make constructor more readable

代码示例来源:origin: stanfordnlp/CoreNLP

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);

代码示例来源:origin: libgdx/libgdx

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());

代码示例来源:origin: pmd/pmd

private JButton createGoButton() {
  JButton b = new JButton("Go");
  b.setMnemonic('g');
  b.addActionListener(new ShowListener());
  b.addActionListener(new XPathListener());
  b.addActionListener(new DFAListener());
  b.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      saveSettings();
    }
  });
  return b;
}

代码示例来源:origin: stanfordnlp/CoreNLP

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;
}

代码示例来源:origin: skylot/jadx

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);

代码示例来源:origin: gocd/gocd

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());
    }
  });
}

代码示例来源:origin: stanfordnlp/CoreNLP

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;
}

相关文章

JButton类方法