Example usage for javax.swing JMenuItem setMnemonic

List of usage examples for javax.swing JMenuItem setMnemonic

Introduction

In this page you can find the example usage for javax.swing JMenuItem setMnemonic.

Prototype

@BeanProperty(visualUpdate = true, description = "the keyboard character mnemonic")
public void setMnemonic(int mnemonic) 

Source Link

Document

Sets the keyboard mnemonic on the current model.

Usage

From source file:fi.smaa.jsmaa.gui.SMAATRIGUIFactory.java

@Override
protected JMenu buildResultsMenu() {
    JMenu resultsMenu = new JMenu("Results");
    resultsMenu.setMnemonic('r');
    JMenuItem racsItem = new JMenuItem("Category acceptability indices",
            ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_RANKACCEPTABILITIES));
    racsItem.setMnemonic('r');

    racsItem.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            Focuser.focus(tree, treeModel, treeModel.getCatAccNode());
        }//  w  ww .j av  a2s  .c  o  m
    });

    resultsMenu.add(racsItem);
    return resultsMenu;
}

From source file:qmod.generator.MainWindow.java

@SuppressWarnings("unchecked")
public MainWindow() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setTitle("Quick Mod Generator");

    JLabel lblAuthors = new JLabel("Authors:");

    authorField1 = new JTextField();
    authorField1.setColumns(25);//from  w  ww . ja  v a  2s .c  o  m

    JButton btnGenerateFile = new JButton("Generate File");
    btnGenerateFile.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            writeFiles();
        }
    });

    authCombo1.setFont(new Font("Dialog", Font.BOLD, 8));
    authCombo1.setModel(
            (ComboBoxModel<Object>) new DefaultComboBoxModel<Object>(new String[] { "Author", "Maintainer" }));
    authCombo1.setSelectedIndex(0);

    authCombo2.setFont(new Font("Dialog", Font.BOLD, 8));
    authCombo2.setModel(
            (ComboBoxModel<Object>) new DefaultComboBoxModel<Object>(new String[] { "Author", "Maintainer" }));
    authCombo2.setSelectedIndex(0);

    authorField2 = new JTextField();
    authorField2.setColumns(25);

    authCombo3.setFont(new Font("Dialog", Font.BOLD, 8));
    authCombo3.setModel(
            (ComboBoxModel<Object>) new DefaultComboBoxModel<Object>(new String[] { "Author", "Maintainer" }));
    authCombo3.setSelectedIndex(0);

    authorField3 = new JTextField();
    authorField3.setColumns(25);

    JLabel lblCategories = new JLabel("Categories:");

    categoriesField = new JTextField();
    categoriesField.setColumns(10);

    JLabel lblDescription = new JLabel("Description:");

    JEditorPane descriptionField = new JEditorPane();

    JLabel lblLicense = new JLabel("License:");

    licenseField = new JTextField();
    licenseField.setColumns(10);
    GroupLayout groupLayout = new GroupLayout(getContentPane());
    groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(groupLayout.createSequentialGroup().addContainerGap()
                    .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout
                            .createSequentialGroup()
                            .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout
                                    .createParallelGroup(Alignment.TRAILING).addComponent(btnGenerateFile)
                                    .addGroup(groupLayout.createSequentialGroup().addComponent(lblAuthors)
                                            .addPreferredGap(ComponentPlacement.RELATED).addGroup(groupLayout
                                                    .createParallelGroup(Alignment.LEADING).addGroup(groupLayout
                                                            .createSequentialGroup()
                                                            .addComponent(
                                                                    authCombo2, GroupLayout.PREFERRED_SIZE, 81,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addGap(6).addComponent(authorField2,
                                                                    GroupLayout.PREFERRED_SIZE, 192,
                                                                    GroupLayout.PREFERRED_SIZE))
                                                    .addGroup(groupLayout.createSequentialGroup().addComponent(
                                                            authCombo1, GroupLayout.PREFERRED_SIZE, 81,
                                                            GroupLayout.PREFERRED_SIZE).addPreferredGap(
                                                                    ComponentPlacement.RELATED)
                                                            .addComponent(
                                                                    authorField1, GroupLayout.DEFAULT_SIZE, 264,
                                                                    Short.MAX_VALUE))
                                                    .addGroup(groupLayout.createSequentialGroup()
                                                            .addComponent(authCombo3,
                                                                    GroupLayout.PREFERRED_SIZE, 81,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addGap(6).addGroup(groupLayout.createParallelGroup(
                                                                    Alignment.LEADING).addComponent(
                                                                            descriptionField)
                                                                    .addGroup(groupLayout
                                                                            .createParallelGroup(
                                                                                    Alignment.LEADING, false)
                                                                            .addComponent(categoriesField)
                                                                            .addComponent(
                                                                                    authorField3,
                                                                                    GroupLayout.DEFAULT_SIZE,
                                                                                    192, Short.MAX_VALUE))
                                                                    .addGroup(groupLayout
                                                                            .createSequentialGroup()
                                                                            .addComponent(licenseField,
                                                                                    GroupLayout.DEFAULT_SIZE,
                                                                                    192, Short.MAX_VALUE)
                                                                            .addPreferredGap(
                                                                                    ComponentPlacement.RELATED)))))))
                                    .addComponent(lblCategories).addComponent(lblDescription))
                            .addGap(84))
                            .addGroup(groupLayout.createSequentialGroup().addComponent(lblLicense)
                                    .addContainerGap(377, Short.MAX_VALUE)))));
    groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout
            .createSequentialGroup().addContainerGap()
            .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblAuthors)
                    .addComponent(authorField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(authCombo1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                    .addComponent(authCombo2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addGroup(groupLayout.createSequentialGroup().addGap(3).addComponent(authorField2,
                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                    .addComponent(authCombo3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addGroup(groupLayout.createSequentialGroup().addGap(3).addComponent(authorField3,
                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(lblCategories)
                    .addComponent(categoriesField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(lblDescription)
                    .addComponent(descriptionField, GroupLayout.PREFERRED_SIZE, 100,
                            GroupLayout.PREFERRED_SIZE))
            .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                    .addGroup(groupLayout.createSequentialGroup().addGap(9).addComponent(lblLicense))
                    .addGroup(groupLayout.createSequentialGroup().addPreferredGap(ComponentPlacement.RELATED)
                            .addComponent(licenseField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)))
            .addPreferredGap(ComponentPlacement.RELATED, 322, Short.MAX_VALUE).addComponent(btnGenerateFile)
            .addContainerGap()));
    getContentPane().setLayout(groupLayout);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic('F');
    menuBar.add(mnFile);

    JMenuItem mntmNew = new JMenuItem("New");
    mntmNew.setMnemonic(KeyEvent.VK_N);
    mnFile.add(mntmNew);

    JMenuItem mntmOpen = new JMenuItem("Open");
    mnFile.add(mntmOpen);

    JMenuItem mntmSave = new JMenuItem("Save");
    mnFile.add(mntmSave);

    JMenuItem mntmExit = new JMenuItem("Exit");
    mntmExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            System.exit(0);
        }
    });
    mntmExit.setMnemonic(KeyEvent.VK_X);
    mnFile.add(mntmExit);
}

From source file:be.fedict.eid.tsl.tool.TslTool.java

private JMenuItem addActionMenuItem(String text, int mnemonic, String actionCommand, JMenu menu,
        boolean enabled) {
    JMenuItem menuItem = new JMenuItem(text);
    menuItem.setMnemonic(mnemonic);
    menuItem.setActionCommand(actionCommand);
    menuItem.addActionListener(this);
    menuItem.setEnabled(enabled);//from  ww  w  .  ja v  a 2  s .  c o  m
    menu.add(menuItem);
    return menuItem;
}

From source file:cz.lidinsky.editor.Menu.java

protected void setLabel(final JMenuItem menuItem, final String label) {
    if (label != null) {
        int mnemonicIndex = label.indexOf('_');
        if (mnemonicIndex >= 0) {
            String text = StringUtils.remove(label, '_');
            int key = text.codePointAt(mnemonicIndex);
            menuItem.setText(text);//from  ww w .  j  ava2s  .c o m
            menuItem.setMnemonic(key);
        } else {
            menuItem.setText(label);
        }
    }
}

From source file:edu.harvard.mcz.imagecapture.BulkMediaFrame.java

private void init() {
    thisFrame = this;
    setTitle("BulkMedia Preparation");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 902, 174);//from w  w w.ja  v a  2 s  .com

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic(KeyEvent.VK_F);
    menuBar.add(mnFile);

    JMenuItem mntmPrepareDirectory = new JMenuItem("Prepare Directory");
    mntmPrepareDirectory.setMnemonic(KeyEvent.VK_D);
    mntmPrepareDirectory.addActionListener(new PrepareDirectoryAction());
    mnFile.add(mntmPrepareDirectory);

    JMenuItem mntmNewMenuItem = new JMenuItem("Exit");
    mntmNewMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            done();
        }
    });

    JMenuItem mntmNewMenuItem_1 = new JMenuItem("Edit Properties");
    mntmNewMenuItem_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            PropertiesEditor p = new PropertiesEditor();
            p.pack();
            p.setVisible(true);
        }
    });
    mnFile.add(mntmNewMenuItem_1);
    mntmNewMenuItem.setMnemonic(KeyEvent.VK_X);
    mntmNewMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    mnFile.add(mntmNewMenuItem);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(new BorderLayout(0, 0));

    JPanel panel = new JPanel();
    contentPane.add(panel, BorderLayout.CENTER);
    panel.setLayout(new GridLayout(3, 2, 0, 0));

    JLabel lblBaseUri = new JLabel("Base URI (first part of path to images on the web)");
    lblBaseUri.setHorizontalAlignment(SwingConstants.TRAILING);
    panel.add(lblBaseUri, "2, 2");

    textField = new JTextField();
    textField.setEditable(false);
    textField.setText(Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_IMAGEBASEURI));
    panel.add(textField);
    textField.setColumns(10);

    JLabel lblNewLabel = new JLabel("Local Path To Base (local mount path that maps to base URI)");
    lblNewLabel.setHorizontalAlignment(SwingConstants.TRAILING);
    panel.add(lblNewLabel);

    textField_1 = new JTextField();
    textField_1.setEditable(false);
    textField_1.setText(Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_IMAGEBASE));
    panel.add(textField_1);
    textField_1.setColumns(10);

    JLabel lblBeforeExitingWait = new JLabel(
            "Before exiting wait for both the Done and Thumbnails Built messages.");
    panel.add(lblBeforeExitingWait);

    JLabel lblThumbnailGenerationIs = new JLabel("Thumbnail generation is not reported on the progress bar.");
    panel.add(lblThumbnailGenerationIs);

    progressBar = new JProgressBar();
    progressBar.setStringPainted(false);
    contentPane.add(progressBar, BorderLayout.NORTH);

    JPanel panel_1 = new JPanel();
    contentPane.add(panel_1, BorderLayout.SOUTH);

    JButton btnPrepareDirectory = new JButton("Run");
    btnPrepareDirectory.setToolTipText("Select a directory and prepare a bulk media file for images therein.");
    panel_1.add(btnPrepareDirectory);
    btnPrepareDirectory.addActionListener(new PrepareDirectoryAction());
    btnPrepareDirectory.setPreferredSize(new Dimension(80, 25));

    JButton btnExit = new JButton("Exit");
    btnExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            done();
        }
    });
    panel_1.add(btnExit);
}

From source file:TextCutPaste.java

/**
 * Create an Edit menu to support cut/copy/paste.
 *//* w  w  w. j  a  v a  2 s.  c  o  m*/
public JMenuBar createMenuBar() {
    JMenuItem menuItem = null;
    JMenuBar menuBar = new JMenuBar();
    JMenu mainMenu = new JMenu("Edit");
    mainMenu.setMnemonic(KeyEvent.VK_E);

    menuItem = new JMenuItem(new DefaultEditorKit.CutAction());
    menuItem.setText("Cut");
    menuItem.setMnemonic(KeyEvent.VK_T);
    mainMenu.add(menuItem);

    menuItem = new JMenuItem(new DefaultEditorKit.CopyAction());
    menuItem.setText("Copy");
    menuItem.setMnemonic(KeyEvent.VK_C);
    mainMenu.add(menuItem);

    menuItem = new JMenuItem(new DefaultEditorKit.PasteAction());
    menuItem.setText("Paste");
    menuItem.setMnemonic(KeyEvent.VK_P);
    mainMenu.add(menuItem);

    menuBar.add(mainMenu);
    return menuBar;
}

From source file:StocksTable5.java

protected JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();

    JMenu mFile = new JMenu("File");
    mFile.setMnemonic('f');

    JMenuItem mData = new JMenuItem("Retrieve Data...");
    mData.setMnemonic('r');
    ActionListener lstData = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            retrieveData();/*from w  ww. jav a2  s .c  om*/
        }
    };
    mData.addActionListener(lstData);
    mFile.add(mData);
    mFile.addSeparator();

    JMenuItem mExit = new JMenuItem("Exit");
    mExit.setMnemonic('x');
    ActionListener lstExit = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    };
    mExit.addActionListener(lstExit);
    mFile.add(mExit);
    menuBar.add(mFile);

    return menuBar;
}

From source file:io.github.dsheirer.gui.SDRTrunk.java

/**
 * Initialize the contents of the frame.
 *//*ww  w .  j a va2s.co  m*/
private void initGUI() {
    mMainGui.setLayout(new MigLayout("insets 0 0 0 0 ", "[grow,fill]", "[grow,fill]"));

    /**
     * Setup main JFrame window
     */
    mTitle = SystemProperties.getInstance().getApplicationName();
    mMainGui.setTitle(mTitle);
    mMainGui.setBounds(100, 100, 1280, 800);
    mMainGui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Set preferred sizes to influence the split
    mSpectralPanel.setPreferredSize(new Dimension(1280, 300));
    mControllerPanel.setPreferredSize(new Dimension(1280, 500));

    mSplitPane = new JideSplitPane(JideSplitPane.VERTICAL_SPLIT);
    mSplitPane.setDividerSize(5);
    mSplitPane.add(mSpectralPanel);
    mSplitPane.add(mControllerPanel);

    mBroadcastStatusVisible = SystemProperties.getInstance().get(PROPERTY_BROADCAST_STATUS_VISIBLE, false);

    //Show broadcast status panel when user requests - disabled by default
    if (mBroadcastStatusVisible) {
        mSplitPane.add(getBroadcastStatusPanel());
    }

    mMainGui.add(mSplitPane, "cell 0 0,span,grow");

    /**
     * Menu items
     */
    JMenuBar menuBar = new JMenuBar();
    mMainGui.setJMenuBar(menuBar);

    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    JMenuItem logFilesMenu = new JMenuItem("Logs & Recordings");
    logFilesMenu.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                Desktop.getDesktop().open(getHomePath().toFile());
            } catch (Exception e) {
                mLog.error("Couldn't open file explorer");

                JOptionPane.showMessageDialog(mMainGui,
                        "Can't launch file explorer - files are located at: " + getHomePath().toString(),
                        "Can't launch file explorer", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    fileMenu.add(logFilesMenu);

    JMenuItem settingsMenu = new JMenuItem("Icon Manager");
    settingsMenu.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            mIconManager.showEditor(mMainGui);
        }
    });
    fileMenu.add(settingsMenu);

    fileMenu.add(new JSeparator());

    JMenuItem exitMenu = new JMenuItem("Exit");
    exitMenu.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    fileMenu.add(exitMenu);

    JMenu viewMenu = new JMenu("View");

    viewMenu.add(new BroadcastStatusVisibleMenuItem(mControllerPanel));

    menuBar.add(viewMenu);

    JMenuItem screenCaptureItem = new JMenuItem("Screen Capture");

    screenCaptureItem.setMnemonic(KeyEvent.VK_C);
    screenCaptureItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK));

    screenCaptureItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                Robot robot = new Robot();

                final BufferedImage image = robot.createScreenCapture(mMainGui.getBounds());

                SystemProperties props = SystemProperties.getInstance();

                Path capturePath = props.getApplicationFolder("screen_captures");

                if (!Files.exists(capturePath)) {
                    try {
                        Files.createDirectory(capturePath);
                    } catch (IOException e) {
                        mLog.error("Couldn't create 'screen_captures' " + "subdirectory in the "
                                + "SDRTrunk application directory", e);
                    }
                }

                String filename = TimeStamp.getTimeStamp("_") + "_screen_capture.png";

                final Path captureFile = capturePath.resolve(filename);

                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            ImageIO.write(image, "png", captureFile.toFile());
                        } catch (IOException e) {
                            mLog.error("Couldn't write screen capture to " + "file [" + captureFile.toString()
                                    + "]", e);
                        }
                    }
                });
            } catch (AWTException e) {
                mLog.error("Exception while taking screen capture", e);
            }
        }
    });

    menuBar.add(screenCaptureItem);
}

From source file:DragColorTextFieldDemo.java

public JMenuBar createMenuBar() {
    JMenuItem menuItem = null;
    JMenuBar menuBar = new JMenuBar();
    JMenu mainMenu = new JMenu("Edit");
    mainMenu.setMnemonic(KeyEvent.VK_E);

    menuItem = new JMenuItem(new DefaultEditorKit.CutAction());
    menuItem.setText("Cut");
    menuItem.setMnemonic(KeyEvent.VK_T);
    mainMenu.add(menuItem);/* w  w w .  jav a2s.  c o m*/
    menuItem = new JMenuItem(new DefaultEditorKit.CopyAction());
    menuItem.setText("Copy");
    menuItem.setMnemonic(KeyEvent.VK_C);
    mainMenu.add(menuItem);
    menuItem = new JMenuItem(new DefaultEditorKit.PasteAction());
    menuItem.setText("Paste");
    menuItem.setMnemonic(KeyEvent.VK_P);
    mainMenu.add(menuItem);

    menuBar.add(mainMenu);
    return menuBar;
}

From source file:edu.harvard.mcz.imagecapture.SpecimenPartAttributeDialog.java

private void init() {
    thisDialog = this;
    setBounds(100, 100, 820, 335);/* w ww  . j  a v a2  s . co m*/
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    JPanel panel = new JPanel();
    panel.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, }));
    {
        JLabel lblAttributeType = new JLabel("Attribute Type");
        panel.add(lblAttributeType, "2, 2, right, default");
    }
    {
        comboBoxType = new JComboBox();
        comboBoxType.setModel(new DefaultComboBoxModel(
                new String[] { "caste", "scientific name", "sex", "life stage", "part association" }));
        comboBoxType.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                String item = comboBoxType.getSelectedItem().toString();
                if (item != null) {
                    comboBoxValue.setEditable(false);
                    if (item.equals("scientific name")) {
                        comboBoxValue.setEditable(true);
                    }
                    if (item.equals("sex")) {
                        comboBoxValue.setModel(new DefaultComboBoxModel(Sex.getSexValues()));
                    }
                    if (item.equals("life stage")) {
                        comboBoxValue.setModel(new DefaultComboBoxModel(LifeStage.getLifeStageValues()));
                    }
                    if (item.equals("caste")) {
                        comboBoxValue.setModel(new DefaultComboBoxModel(Caste.getCasteValues()));
                    }
                    if (item.equals("part association")) {
                        comboBoxValue
                                .setModel(new DefaultComboBoxModel(PartAssociation.getPartAssociationValues()));
                    }
                }
            }

        });
        panel.add(comboBoxType, "4, 2, fill, default");
    }
    {
        JLabel lblValue = new JLabel("Value");
        panel.add(lblValue, "2, 4, right, default");
    }
    {
        comboBoxValue = new JComboBox();
        comboBoxValue.setModel(new DefaultComboBoxModel(Caste.getCasteValues()));

        panel.add(comboBoxValue, "4, 4, fill, default");
    }
    {
        JLabel lblUnits = new JLabel("Units");
        panel.add(lblUnits, "2, 6, right, default");
    }
    {
        textFieldUnits = new JTextField();
        panel.add(textFieldUnits, "4, 6, fill, default");
        textFieldUnits.setColumns(10);
    }
    {
        JLabel lblRemarks = new JLabel("Remarks");
        panel.add(lblRemarks, "2, 8, right, default");
    }
    contentPanel.setLayout(new BorderLayout(0, 0));
    contentPanel.add(panel, BorderLayout.WEST);
    {
        textFieldRemarks = new JTextField();
        panel.add(textFieldRemarks, "4, 8, fill, default");
        textFieldRemarks.setColumns(10);
    }
    {
        JButton btnAdd = new JButton("Add");
        btnAdd.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                SpecimenPartAttribute newAttribs = new SpecimenPartAttribute();
                newAttribs.setAttributeType(comboBoxType.getSelectedItem().toString());
                newAttribs.setAttributeValue(comboBoxValue.getSelectedItem().toString());
                newAttribs.setAttributeUnits(textFieldUnits.getText());
                newAttribs.setAttributeRemark(textFieldRemarks.getText());
                newAttribs.setSpecimenPartId(parentPart);
                newAttribs.setAttributeDeterminer(Singleton.getSingletonInstance().getUserFullName());
                parentPart.getAttributeCollection().add(newAttribs);
                SpecimenPartAttributeLifeCycle sls = new SpecimenPartAttributeLifeCycle();
                try {
                    sls.attachDirty(newAttribs);
                } catch (SaveFailedException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                ((AbstractTableModel) table.getModel()).fireTableDataChanged();
            }
        });
        panel.add(btnAdd, "4, 10");
    }
    try {
        JLabel lblNewLabel = new JLabel(parentPart.getSpecimenId().getBarcode() + ":" + parentPart.getPartName()
                + " " + parentPart.getPreserveMethod() + " (" + parentPart.getLotCount()
                + ")    Right click on table to edit attributes.");
        contentPanel.add(lblNewLabel, BorderLayout.NORTH);
    } catch (Exception e) {
        JLabel lblNewLabel = new JLabel("No Specimen");
        contentPanel.add(lblNewLabel, BorderLayout.NORTH);
    }
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("caste");
    JComboBox comboBox1 = new JComboBox();
    for (int i = 0; i < Caste.getCasteValues().length; i++) {
        comboBox1.addItem(Caste.getCasteValues()[i]);
    }
    JScrollPane scrollPane = new JScrollPane();

    table = new JTable(new SpecimenPartsAttrTableModel(
            (Collection<SpecimenPartAttribute>) parentPart.getAttributeCollection()));

    //table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(comboBox));   

    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                clickedOnRow = ((JTable) e.getComponent()).getSelectedRow();
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                clickedOnRow = ((JTable) e.getComponent()).getSelectedRow();
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    popupMenu = new JPopupMenu();

    JMenuItem mntmCloneRow = new JMenuItem("Edit Row");
    mntmCloneRow.setMnemonic(KeyEvent.VK_E);
    mntmCloneRow.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                // Launch a dialog to edit the selected row.
                SpecimenPartAttribEditDialog popup = new SpecimenPartAttribEditDialog(
                        ((SpecimenPartsAttrTableModel) table.getModel()).getRowObject(clickedOnRow));
                popup.setVisible(true);
            } catch (Exception ex) {
                log.error(ex.getMessage());
                JOptionPane.showMessageDialog(thisDialog,
                        "Failed to edit a part attribute row. " + ex.getMessage());
            }
        }
    });
    popupMenu.add(mntmCloneRow);

    JMenuItem mntmDeleteRow = new JMenuItem("Delete Row");
    mntmDeleteRow.setMnemonic(KeyEvent.VK_D);
    mntmDeleteRow.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                if (clickedOnRow >= 0) {
                    ((SpecimenPartsAttrTableModel) table.getModel()).deleteRow(clickedOnRow);
                }
            } catch (Exception ex) {
                log.error(ex.getMessage());
                JOptionPane.showMessageDialog(thisDialog,
                        "Failed to delete a part attribute row. " + ex.getMessage());
            }
        }
    });
    popupMenu.add(mntmDeleteRow);

    // TODO: Enable controlled value editing of selected row.

    // table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox1));

    scrollPane.setViewportView(table);
    contentPanel.add(scrollPane, BorderLayout.EAST);
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            okButton = new JButton("OK");
            okButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    okButton.grabFocus();
                    thisDialog.setVisible(false);
                }
            });
            okButton.setActionCommand("OK");
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    thisDialog.setVisible(false);
                }
            });
            cancelButton.setActionCommand("Cancel");
            buttonPane.add(cancelButton);
        }
    }
}