List of usage examples for java.awt.event ActionListener ActionListener
ActionListener
From source file:ModelJTable.java
public ModelJTable() { super();//w ww.j a v a 2 s. c o m model = new DefaultTableModel(); model.addColumn("First Name"); model.addColumn("Last Name"); model.addColumn("Years"); String[] socrates = { "Socrates", "", "469-399 B.C." }; model.addRow(socrates); String[] plato = { "Plato", "", "428-347 B.C." }; model.addRow(plato); String[] aquinas = { "Thomas", "Aquinas", "1225-1274" }; model.addRow(aquinas); String[] kierkegaard = { "Soren", "Kierkegaard", "1813-1855" }; model.addRow(kierkegaard); String[] kant = { "Immanuel", "Kant", "1724-1804" }; model.addRow(kant); String[] nietzsche = { "Friedrich", "Nietzsche", "1844-1900" }; model.addRow(nietzsche); String[] arendt = { "Hannah", "Arendt", "1906-1975" }; model.addRow(arendt); table = new JTable(model); JButton addButton = new JButton("Add Philosopher"); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String[] philosopher = { "", "", "" }; model.addRow(philosopher); } }); JButton removeButton = new JButton("Remove Selected Philosopher"); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { model.removeRow(table.getSelectedRow()); } }); JPanel inputPanel = new JPanel(); inputPanel.add(addButton); inputPanel.add(removeButton); Container container = getContentPane(); container.add(new JScrollPane(table), BorderLayout.CENTER); container.add(inputPanel, BorderLayout.NORTH); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(400, 300); setVisible(true); }
From source file:com.mirth.connect.manager.HeapSizeDialog.java
public HeapSizeDialog(String heapSize) { super(PlatformUI.MANAGER_DIALOG, true); managerController = ManagerController.getInstance(); getRootPane().registerKeyboardAction(new ActionListener() { @Override//from w w w. j av a 2s . co m public void actionPerformed(ActionEvent e) { dispose(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); setResizable(false); setBackground(Color.white); setTitle("Web Start Settings"); getContentPane().setBackground(Color.white); initComponents(); this.heapSize = StringUtils.isEmpty(heapSize) ? "512m" : heapSize; String heapSizeOption = HeapSize.toDisplayName(heapSize); if (StringUtils.isBlank(heapSizeOption)) { heapSizeOption = this.heapSize; } // Add any non-default properties to the model String property = (String) managerController.getServerProperties() .getProperty(ManagerConstants.ADMINISTRATOR_MAX_HEAP_SIZE); if (!heapSizeComboboxModel.contains(property) && !heapSizeComboboxModel.contains(HeapSize.toDisplayName(property))) { heapSizeComboboxModel.add(formatCustomProperty(property)); } // Resort list by sizes List<String> mbList = new ArrayList<String>(); List<String> gbList = new ArrayList<String>(); for (String size : heapSizeComboboxModel) { if (size.contains("M")) { mbList.add(size); } else { gbList.add(size); } } Collections.sort(mbList); Collections.sort(gbList); mbList.addAll(gbList); heapSizeComboBox = new JComboBox(mbList.toArray()); heapSizeComboBox.getModel().setSelectedItem(formatCustomProperty(heapSizeOption)); initLayout(); pack(); setLocationRelativeTo(PlatformUI.MANAGER_DIALOG); setVisible(true); }
From source file:Main.java
protected void showMenu(int x, int y) { JPopupMenu popup = new JPopupMenu(); JMenuItem mi = new JMenuItem("Delete"); TreePath path = tree.getSelectionPath(); Object node = path.getLastPathComponent(); if (node == tree.getModel().getRoot()) { mi.setEnabled(false);/*from w w w . j a va 2s . c o m*/ } popup.add(mi); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { deleteSelectedItems(); } }); popup.show(tree, x, y); }
From source file:Main.java
public Main() { super("Undo/Redo Demo"); undoButton.setEnabled(false);/*from w w w. j a va 2 s .c om*/ redoButton.setEnabled(false); JPanel buttonPanel = new JPanel(new GridLayout()); buttonPanel.add(undoButton); buttonPanel.add(redoButton); JScrollPane scroller = new JScrollPane(textArea); getContentPane().add(buttonPanel, BorderLayout.NORTH); getContentPane().add(scroller, BorderLayout.CENTER); textArea.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { undoManager.addEdit(e.getEdit()); updateButtons(); } }); undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { undoManager.undo(); } catch (CannotRedoException cre) { cre.printStackTrace(); } updateButtons(); } }); redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { undoManager.redo(); } catch (CannotRedoException cre) { cre.printStackTrace(); } updateButtons(); } }); setSize(400, 300); setVisible(true); }
From source file:com.archivas.clienttools.arcmover.gui.panels.CopyOptionsPanel.java
public CopyOptionsPanel(JobDialog jobDialog, CopyJob copyJob) { this.jobDialog = jobDialog; layoutGuiComponents();// w w w . j a v a2 s . co m initState(copyJob.ignoreConflicts()); ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent e) { fieldChanged(); } }; ignoreConflictsCheckbox.addActionListener(l); }
From source file:Main.java
protected JMenuBar createMenuBar() { final JMenuBar menuBar = new JMenuBar(); JMenu mFont = new JMenu("Font"); mFont.setMnemonic('o'); ButtonGroup group = new ButtonGroup(); fontMenus = new JMenuItem[FontName.length]; for (int k = 0; k < FontName.length; k++) { int m = k + 1; fontMenus[k] = new JRadioButtonMenuItem(m + " " + FontName[k]); boolean selected = (k == 0); fontMenus[k].setSelected(selected); fontMenus[k].setMnemonic('1' + k); fontMenus[k].setFont(fonts[k]);//from w w w. j a v a 2 s. co m fontMenus[k].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(((JComponent) arg0.getSource()).getFont()); } }); group.add(fontMenus[k]); mFont.add(fontMenus[k]); } menuBar.add(mFont); return menuBar; }
From source file:ScreenCapture.java
public ScreenCapture(String title) { super(title); setDefaultCloseOperation(EXIT_ON_CLOSE); JMenuBar mb = new JMenuBar(); JMenu menu = new JMenu("File"); ActionListener al;/*from w w w .ja va 2 s . c om*/ JMenuItem mi = new JMenuItem("Save"); al = new ActionListener() { public void actionPerformed(ActionEvent e) { save(); } }; mi.addActionListener(al); menu.add(mi); mb.add(menu); menu = new JMenu("Capture"); mi = new JMenuItem("Capture"); al = new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); BufferedImage biScreen = robot.createScreenCapture(rectScreenSize); setVisible(true); ia.setImage(biScreen); jsp.getHorizontalScrollBar().setValue(0); jsp.getVerticalScrollBar().setValue(0); } }; mi.addActionListener(al); menu.add(mi); mb.add(menu); mi = new JMenuItem("Crop"); al = new ActionListener() { public void actionPerformed(ActionEvent e) { if (ia.crop()) { jsp.getHorizontalScrollBar().setValue(0); jsp.getVerticalScrollBar().setValue(0); } } }; mi.addActionListener(al); menu.add(mi); mb.add(menu); setJMenuBar(mb); getContentPane().add(jsp = new JScrollPane(ia)); setVisible(true); }
From source file:UndoRedoTextArea.java
public UndoRedoTextArea() { super("Undo/Redo Demo"); undoButton.setEnabled(false);/*from w w w. j a va 2 s .com*/ redoButton.setEnabled(false); JPanel buttonPanel = new JPanel(new GridLayout()); buttonPanel.add(undoButton); buttonPanel.add(redoButton); JScrollPane scroller = new JScrollPane(textArea); getContentPane().add(buttonPanel, BorderLayout.NORTH); getContentPane().add(scroller, BorderLayout.CENTER); textArea.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { undoManager.addEdit(e.getEdit()); updateButtons(); } }); undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { undoManager.undo(); } catch (CannotRedoException cre) { cre.printStackTrace(); } updateButtons(); } }); redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { undoManager.redo(); } catch (CannotRedoException cre) { cre.printStackTrace(); } updateButtons(); } }); setSize(400, 300); setVisible(true); }
From source file:MyApplet.java
private void guiInit() { // Set the applet to use flow layout. setLayout(new FlowLayout()); // Create two buttons and a label. jbtnOne = new JButton("One"); jbtnTwo = new JButton("Two"); jlab = new JLabel("Press a button."); // Add action listeners for the buttons. jbtnOne.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent le) { jlab.setText("Button One pressed."); }//from ww w. j a va 2s . com }); jbtnTwo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent le) { jlab.setText("Button Two pressed."); } }); // Add the components to the applet's content pane. getContentPane().add(jbtnOne); getContentPane().add(jbtnTwo); getContentPane().add(jlab); }
From source file:components.ListDialogRunner.java
public static JPanel createUI() { //Create the labels. JLabel intro = new JLabel("The chosen name:"); final JLabel name = new JLabel(names[1]); intro.setLabelFor(name);//from w w w . j ava2 s. c om //Use a wacky font if it exists. If not, this falls //back to a font we know exists. name.setFont(getAFont()); //Create the button. final JButton button = new JButton("Pick a new name..."); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String selectedName = ListDialog.showDialog(frame, button, "Baby names ending in O:", "Name Chooser", names, name.getText(), "Cosmo "); name.setText(selectedName); } }); //Create the panel we'll return and set up the layout. JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20)); intro.setAlignmentX(JComponent.CENTER_ALIGNMENT); name.setAlignmentX(JComponent.CENTER_ALIGNMENT); button.setAlignmentX(JComponent.CENTER_ALIGNMENT); //Add the labels to the content pane. panel.add(intro); panel.add(Box.createVerticalStrut(5)); //extra space panel.add(name); //Add a vertical spacer that also guarantees us a minimum width: panel.add(Box.createRigidArea(new Dimension(150, 10))); //Add the button. panel.add(button); return panel; }