⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmcomboboxcelleditor.java

📁 梦界家园程序开发基底框架
💻 JAVA
字号:
package jm.framework.gui.module.editer ;

import java.awt.Color;
import java.awt.Component;
import java.util.Vector;

import javax.swing.AbstractCellEditor;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.table.TableCellEditor;
import javax.swing.tree.TreeCellEditor;

import jm.framework.gui.module.JMComboBox;
import jm.framework.gui.module.JMScrollPane;
import jm.framework.gui.module.render.JMListCellRenderer;
import jm.util.JMVal;

public class JMComboBoxCellEditor
    extends AbstractCellEditor implements TableCellEditor , TreeCellEditor
{
    /**
	 * 
	 */
	private static final long serialVersionUID = 4714995273824228520L;
	JMScrollPane bkg = new JMScrollPane () ;
    private DefaultComboBoxModel oModel = null ;
    private JMComboBox comboBox = null ;
    public JMComboBoxCellEditor ( Vector<String> val , Color selBackColor )
    {
        super () ;
        try
        {
            oModel = new DefaultComboBoxModel ( ( val != null ) ? val : new Vector () ) ;
            comboBox = new JMComboBox ( oModel ) ;
            comboBox.setBorder ( null ) ;
            bkg.setBorder ( null ) ;
            comboBox.setOpaque ( true ) ;
            comboBox.setBackground ( Color.white ) ;
            comboBox.setRenderer ( new JMListCellRenderer ( selBackColor ) ) ;
            jbInit () ;
        }
        catch ( Exception ex )
        {
            ex.printStackTrace () ;
        }
    }
    public JMComboBox getCellComboBox()
        {
            return comboBox;
    }
    public Component getTableCellEditorComponent (
        JTable table ,
        Object value ,
        boolean isSelected ,
        int row ,
        int column )
    {
        try
        {
            JMVal cellval = (JMVal)value;
            comboBox.setSelectedItem ( cellval.getStringValue() ) ;
            comboBox.setVisible ( true ) ;
            return bkg ;
        }
        catch ( Exception e )
        {
            return bkg ;
        }
    }

    /**
     * 僄僨傿僞偺乽弶婜抣乿傪愝掕偟傑偡丅偙傟偵傛傝僄僨傿僞偱 stopEditing 偑屇傃弌偝傟丄偦偺偲偒偵僄僨傿僞偑曇廤拞偺応崌偼丄曇廤偝傟偨抣偑堦晹徚幐偡傞偙偲偑偁傝傑偡丅
     * 僋儔僀傾儞僩偺 Component 奒憌偵捛壛偡傞昁梫偺偁傞僐儞億乕僱儞僩傪曉偟傑偡丅偙偺僐儞億乕僱儞僩偑僋儔僀傾儞僩偺奒憌偵慻傒崬傑傟傞偲丄儐乕僓擖椡傪昤夋偍傛傃庴怣偱偒傑偡丅
     * @param tree JTree 僄僨傿僞偵曇廤傪梫媮偟偰偄傞 JTree丅偙偺僷儔儊乕僞偼 null 傕壜
     * @param value Object 曇廤偝傟傞僙儖抣
     * @param isSelected boolean 僙儖偑儗儞僟儕儞僌偲側傝慖戰晹偑僴僀儔僀僩偝傟偰偄傞応崌偼 true
     * @param expanded boolean 僲乕僪偑揥奐偝傟偰偄傞応崌偼 true
     * @param leaf boolean 僲乕僪偑梩僲乕僪偺応崌偼 true
     * @param row int 曇廤拞偺僲乕僪偺峴僀儞僨僢僋僗
     * @return Component 曇廤偺偨傔偺僐儞億乕僱儞僩
     */
    public Component getTreeCellEditorComponent ( JTree tree ,
                                                  Object value ,
                                                  boolean isSelected ,
                                                  boolean expanded ,
                                                  boolean leaf ,
                                                  int row )
    {
        try
        {
            JMVal cellval = (JMVal)value;
            comboBox.setSelectedItem ( cellval.getStringValue() ) ;
            comboBox.setVisible ( true ) ;
            return bkg ;
        }
        catch ( Exception e )
        {
            return bkg ;
        }
    }

    /**
     * Returns the value contained in the editor.
     *
     * @return the value contained in the editor
     * @todo Implement this javax.swing.CellEditor method
     */
    public Object getCellEditorValue ()
    {
        return new JMVal( ""+comboBox.getSelectedItem () );
    }

    private void jbInit ()
        throws Exception
    {
        bkg.setHorizontalScrollBarPolicy ( JMScrollPane.HORIZONTAL_SCROLLBAR_NEVER ) ;
        bkg.setVerticalScrollBarPolicy ( JMScrollPane.VERTICAL_SCROLLBAR_NEVER ) ;
        comboBox.setBackground ( Color.white ) ;
        bkg.setBackground ( Color.white ) ;
        bkg.getViewport ().add ( comboBox ) ;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -