Java JTable Cell Editor createEditableComboBox(String strActionCommand, ActionListener alListener, int iPreferredWidth)

Here you can find the source of createEditableComboBox(String strActionCommand, ActionListener alListener, int iPreferredWidth)

Description

Create editable JComboBox

License

Open Source License

Parameter

Parameter Description
strActionCommand - action command name
alListener - action listener
iPreferredWidth - max width size

Return

initialized JComboBox

Declaration

public static JComboBox<?> createEditableComboBox(String strActionCommand, ActionListener alListener,
        int iPreferredWidth) 

Method Source Code


//package com.java2s;

import java.awt.Dimension;

import java.awt.event.ActionListener;

import javax.swing.JComboBox;

public class Main {

    public static JComboBox<?> createEditableComboBox(String strActionCommand, ActionListener alListener,
            int iPreferredWidth) {
        JComboBox<?> cbResult = new JComboBox<Object>();
        //set preffered width
        if (iPreferredWidth != 0) {
            cbResult.setPreferredSize(new Dimension(iPreferredWidth, cbResult.getPreferredSize().height));
        }/* w  w  w  .j a  va2 s  .co m*/
        //set action command
        if (strActionCommand != null && !strActionCommand.isEmpty()) {
            cbResult.setActionCommand(strActionCommand);
        }
        //check editable flag
        cbResult.setEditable(true);
        //add action listener
        if (alListener != null) {
            cbResult.addActionListener(alListener);
        }
        return cbResult;
    }
}

Related

  1. cancelTableEditing(final JTable table)
  2. createComboBox(Object items[], ActionListener listener, boolean editable)
  3. createTransclucentJTextAreaWithNoBorder(String text, boolean editable, boolean lineWrap, boolean wrapStyleWord)
  4. genHyperLinkEditor(final String uri, final Logger logger)
  5. installSimpleRenderesAndEditors(JTable table)
  6. isEditable(Component comp)