List of usage examples for javax.swing AbstractButton addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:pcgen.gui2.converter.panel.WriteDirectoryPanel.java
@Override public void setupDisplay(JPanel panel, final CDOMObject pc) { panel.setLayout(layout);/* w ww . j a va 2 s . c om*/ Component label = new JLabel("Please select the Directory where Converted files should be written: "); AbstractButton button = new JButton("Browse..."); button.setMnemonic('r'); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setCurrentDirectory(path.getParentFile()); chooser.setSelectedFile(path); while (true) { int open = chooser.showOpenDialog(null); if (open == JFileChooser.APPROVE_OPTION) { File fileToOpen = chooser.getSelectedFile(); if (fileToOpen.isDirectory() && fileToOpen.canRead() && fileToOpen.canWrite()) { path = fileToOpen; pc.put(ObjectKey.WRITE_DIRECTORY, path); fileLabel.setText(path.getAbsolutePath()); PCGenSettings context = PCGenSettings.getInstance(); context.setProperty(PCGenSettings.CONVERT_OUTPUT_SAVE_PATH, path.getAbsolutePath()); showWarning(); break; } JOptionPane.showMessageDialog(null, "Selection must be a valid " + "(readable & writeable) Directory"); chooser.setCurrentDirectory(path.getParentFile()); } else if (open == JFileChooser.CANCEL_OPTION) { break; } } } }); panel.add(label); panel.add(fileLabel); panel.add(button); panel.add(warningLabel); showWarning(); layout.putConstraint(SpringLayout.NORTH, label, 50, SpringLayout.NORTH, panel); layout.putConstraint(SpringLayout.NORTH, fileLabel, 75 + label.getPreferredSize().height, SpringLayout.NORTH, panel); layout.putConstraint(SpringLayout.NORTH, button, 75 + label.getPreferredSize().height, SpringLayout.NORTH, panel); layout.putConstraint(SpringLayout.WEST, label, 25, SpringLayout.WEST, panel); layout.putConstraint(SpringLayout.WEST, fileLabel, 25, SpringLayout.WEST, panel); layout.putConstraint(SpringLayout.EAST, button, -50, SpringLayout.EAST, panel); layout.putConstraint(SpringLayout.NORTH, warningLabel, 20, SpringLayout.SOUTH, fileLabel); layout.putConstraint(SpringLayout.WEST, warningLabel, 25, SpringLayout.WEST, panel); fileLabel.setText(path.getAbsolutePath()); }
From source file:pcgen.gui2.dialog.OptionsPathDialog.java
private void addRadioButton(String text, String command, ButtonGroup group, ActionListener listener, GridBagConstraints gbc) { boolean selected = command.equals(selectedDir); if (selected) { text += " (default)"; //for i18n this will need to be handled differently }// www . j a v a 2s . c o m AbstractButton rButton = new JRadioButton(text); rButton.setActionCommand(command); rButton.setSelected(selected); rButton.addActionListener(listener); group.add(rButton); getContentPane().add(rButton, gbc); }