Java Utililty Methods JTable Cell Editor

List of utility methods to do JTable Cell Editor

Description

The list of methods to do JTable Cell Editor are organized into topic(s).

Method

voidcancelTableEditing(final JTable table)
cancel Table Editing
if (table.isEditing()) {
    int row = table.getEditingRow();
    int col = table.getEditingColumn();
    table.getCellEditor(row, col).cancelCellEditing();
JComboBoxcreateComboBox(Object items[], ActionListener listener, boolean editable)
create Combo Box
JComboBox comboBox = new JComboBox(items);
if (listener != null)
    comboBox.addActionListener(listener);
comboBox.setEditable(editable);
return comboBox;
JComboBoxcreateEditableComboBox(String strActionCommand, ActionListener alListener, int iPreferredWidth)
Create editable JComboBox
JComboBox<?> cbResult = new JComboBox<Object>();
if (iPreferredWidth != 0) {
    cbResult.setPreferredSize(new Dimension(iPreferredWidth, cbResult.getPreferredSize().height));
if (strActionCommand != null && !strActionCommand.isEmpty()) {
    cbResult.setActionCommand(strActionCommand);
cbResult.setEditable(true);
...
JTextAreacreateTransclucentJTextAreaWithNoBorder(String text, boolean editable, boolean lineWrap, boolean wrapStyleWord)
create Transclucent J Text Area With No Border
JTextArea ta = new JTextArea(text);
ta.setEditable(editable);
ta.setLineWrap(lineWrap);
ta.setWrapStyleWord(wrapStyleWord);
ta.setOpaque(false);
ta.setBorder(null);
ta.setBorder(BorderFactory.createEmptyBorder());
ta.setBackground(new Color(0, 0, 0, 0));
...
ComponentgenHyperLinkEditor(final String uri, final Logger logger)
gen Hyper Link Editor
JEditorPane editor = new JEditorPane("text/html", "<html><a href='" + uri + "'>" + uri + "</a>");
editor.setOpaque(false);
editor.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
editor.setEditable(false);
editor.addHyperlinkListener(new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
...
voidinstallSimpleRenderesAndEditors(JTable table)
install Simple Renderes And Editors
Map<Class, Class> map = new HashMap<Class, Class>();
map.put(boolean.class, Boolean.class);
map.put(byte.class, Number.class);
map.put(short.class, Number.class);
map.put(int.class, Number.class);
map.put(long.class, Number.class);
map.put(float.class, Number.class);
map.put(double.class, Number.class);
...
booleanisEditable(Component comp)
return false if Component is not editable, otherwise true
if (comp instanceof JTextComponent) {
    return ((JTextComponent) comp).isEditable();
} else if (comp instanceof JComboBox) {
    return ((JComboBox) comp).isEditable();
else
    return true;
voidprocessEditorRemovel(JTable aTable)
process Editor Removel
AWTEvent currentEvent = EventQueue.getCurrentEvent();
if (currentEvent instanceof KeyEvent) {
    KeyEvent ke = (KeyEvent) currentEvent;
    if (KeyStroke.getKeyStrokeForEvent(ke).equals(TABKEYSTROKE)) {
        int selectedRow = aTable.getSelectedRow();
        if (ke.isShiftDown()) {
            int selectedColumn = aTable.getSelectedColumn() - 1;
            while (selectedColumn >= 0) {
...
voidsetCellEditor(JTable table, int columnIdx, TableCellEditor editor)
set Cell Editor
TableColumn o = table.getColumnModel().getColumn(columnIdx);
o.setCellEditor(editor);
voidsetCharacterAttributes(final AttributeSet attr, final boolean replace, final JEditorPane editorPane, final StyledDocument doc, final MutableAttributeSet inputAttrs)
set Character Attributes
final int selectionStart = editorPane.getSelectionStart();
final int selectionEnd = editorPane.getSelectionEnd();
doc.setCharacterAttributes(selectionStart, selectionEnd - selectionStart, attr, replace);
if (selectionStart == selectionEnd) {
    if (replace) {
        inputAttrs.removeAttributes(inputAttrs.getAttributeNames());
    inputAttrs.addAttributes(attr);
...