📄 jmcheckboxcelleditor.java
字号:
package jm.framework.gui.module.editer ;
import java.awt.Color;
import java.awt.Component;
import javax.swing.AbstractCellEditor;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.table.TableCellEditor;
import javax.swing.tree.TreeCellEditor;
import jm.framework.gui.module.JMCheckBox;
import jm.framework.gui.module.JMItemCode;
import jm.util.JMVList;
import jm.util.JMUtility;
import jm.util.JMVal;
public class JMCheckBoxCellEditor
extends AbstractCellEditor implements TableCellEditor , TreeCellEditor
{
/**
*
*/
private static final long serialVersionUID = -2362859332597741839L;
public static final String CLASS_NAME = "CheckBoxCellEditor" ;
JPanel bkg = new JPanel () ;
private JMCheckBox checkbox = null ;
private JMVList oval = null ;
boolean bshowtex = false ;
Color oselBackColor = null ;
boolean click = false;
/**
* CheckBoxCellEditor
* @param val JMVList val[0]:uncheck,val[1]:check
* @param selBackColor Color
* @param showtext boolean
*/
public JMCheckBoxCellEditor ( JMVList val , Color selBackColor , boolean showtext )
{
super () ;
try
{
checkbox = new JMCheckBox () ;
checkbox.setOpaque ( true ) ;
bshowtex = showtext ;
oval = val ;
oselBackColor = selBackColor ;
jbInit () ;
}
catch ( Exception ex )
{
ex.printStackTrace () ;
}
}
public JMCheckBox getCellJMCheckBox ()
{
return checkbox ;
}
public Component getTableCellEditorComponent (
JTable table ,
Object value ,
boolean isSelected ,
int row , int column )
{
try
{
JMVal cellval = (JMVal)value;
if ( bshowtex ) checkbox.setText ( cellval.getStringValue() ) ;
if (cellval.equals((oval.get(0))))
{
checkbox.setSelected ( false ) ;
}
else
{
checkbox.setSelected ( true ) ;
}
getCellEditorValue ();
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;
if ( bshowtex ) checkbox.setText ( cellval.getStringValue() ) ;
if (cellval.equals((oval.get(0))))
{
checkbox.setSelected ( false ) ;
}
else
{
checkbox.setSelected ( true ) ;
}
getCellEditorValue ();
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 ()
{
if ( oval != null && oval.size () == 2 )
{
if ( checkbox.isSelected () )
return oval.get ( 1 ) ;
else
return oval.get ( 0 ) ;
}
return new JMVal(JMUtility.changNvl( checkbox.getText())) ;
}
private void jbInit ()
throws Exception
{
if ( oselBackColor != null )
{
checkbox.setBackground ( oselBackColor ) ;
bkg.setBackground ( oselBackColor ) ;
}
checkbox.addActionListener ( new java.awt.event.ActionListener ()
{
public void actionPerformed ( java.awt.event.ActionEvent e )
{
// click = true;
checkbox.setFont ( JMItemCode.FT_TABLE_SELECT ) ;
if ( bshowtex ) checkbox.setText ( "" + getCellEditorValue () ) ;
}
} ) ;
bkg.add ( checkbox ) ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -