English 中文(简体)
JCombo JTable 电池内的方框
原标题:JComboBox inside a JTable cell

I m 遇到麻烦,把javax.swing.JComboBox带入一个org.jdesktop.swingx.JXTable电池。 我提出了以前关于这一问题的问题,但没有得到帮助。

我尝试:

colModel.getColumnExt(HDTableAdapter.STATUS).setCellEditor(editorCB);  
colModel.getColumnExt(HDTableAdapter.STATUS).setCellRenderer(rendererCB);

class comboBoxRenderer extends JComboBox implements TableCellRenderer {

    public comboBoxRenderer(String[] items) {
        super(items);
    }

    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        if (isSelected) {
            setForeground(table.getSelectionForeground());
            super.setBackground(table.getSelectionBackground());
        } else {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
        }

        setSelectedItem(value);
        return this;
    }
}

class comboBoxEditor extends DefaultCellEditor {
    public comboBoxEditor(String[] items) {
        super(new JComboBox(items));
    }
}

但是,在这种情况下,我在囚室内得到一个不容置信的ComboBox。

问题回答

页 次 编辑看错了。

class ComboBoxEditor extends DefaultCellEditor {

    public ComboBoxEditor(String[] items) {
    super(new JComboBox(items));
    JCombobxToolTipRenderer renderer = new JCombobxToolTipRenderer();
    ((JComboBox)editorComponent).setRenderer(renderer);
}

public ComboBoxEditor(ComboBoxModel aModel) {
    super(new JComboBox(aModel));
    JCombobxToolTipRenderer renderer = new JCombobxToolTipRenderer();
    ((JComboBox)editorComponent).setRenderer(renderer);
}
}

class JCombobxToolTipRenderer extends DefaultListCellRenderer {

@Override
public Component getListCellRendererComponent(JList list, Object value,
                    int index, boolean isSelected, boolean cellHasFocus) {

    JComponent comp = (JComponent) super.getListCellRendererComponent(list,
            value, index, isSelected, cellHasFocus);

    if (-1 < index && null != value) {
        list.setToolTipText((String) value);
    }
    return comp;
}
}

为此,

class FinCellEditor extends AbstractCellEditor implements TableCellEditor{

    Component component;

    private JTextField text;
    private JComboBox combo;
    private int rowIndex;

       public FinCellEditor(){
                text = new JTextField();
              combo =new JComboBox();
       }

    @Override
        public Object getCellEditorValue() {
               Object select = null;
               if(rowIndex==9||rowIndex==10){
               select = combo.getSelectedItem(); 
               return select;
               }else{    
               if(select!=null){
                  text.selectAll();
               } 
               select = text.getText();
               return select;
               }
        }
    @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
              if (row == 7) {      
                  date.setEnabled(true);
                  rowIndex=row;
                  return date;
              }else if (row == 9) {
                 combo.removeAllItems();
                 combo.addItem("Male");
                 combo.addItem("Female");
                 rowIndex=row;
                 return combo;
            }else if (row == 10) {
                 combo.removeAllItems();
                 combo.addItem("Married");
                 combo.addItem("UnMarried");
                 rowIndex=row;
                 return combo;

           } else {
                text.setEnabled(true);
                rowIndex=row;
                return text;
           }
       }




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签