Checkbox renderer

Hi
i have a data grid with one of its column having check box as
renderer.
check box is visible for only some rows based on a
condition.and this condition is in a function which is called from
updateDiaplayList() function.
but,the checkbox some how appears twice only for the first
row in the data grid.
the condition function is
public function checkDelPermission():void{
var checkpermissioninstance:CheckPermission = new
CheckPermission();
checkpermissioninstance.permissions = [8];
if(data.hasOwnProperty("permission")){
checkpermissioninstance.permBit = data.permission;
var delpermission:ArrayCollection =
checkpermissioninstance.getPermissions()
if(delpermission!=null){
this.logmessage("==== "+data.id+" =========del permisison
=="+ delpermission[0]);
if(delpermission[0]==true){
this.visible = true;
else{
this.visible = false;
else
this.visible = false;
and updatedisplaylist() is
override protected function
updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void
super.updateDisplayList(unscaledWidth,unscaledHeight);
checkDelPermission();
var n:int = numChildren;
for (var i:int = 0; i < n; i++)
var c:DisplayObject = getChildAt(i);
if (!(c is TextField))
c.x = (unscaledWidth - c.width) / 2;
c.y = 0;
the log message is printed twice for the first row data..and
for all other rows in a datagrid,every thing appears as expected.
and this happens randomly and not alwayss..
Thanks
chandana

thank u very much..
in set data method,i added the following
override public function set data(value:Object):void{
if(value != null){
super.data = value;
if((data.chkselected==null) ||
(data.chkselected=="undefined")){
data.chkselected = false;
this.selected = data.chkselected;
this works when i change checkbox selection in each row..
i have another problem..can u please help me in solving this
i have a checkbox as header renderer..
On click, it is selectiing/deselecting only the checkboxes of
rows which are visible and when i scroll the datagrid,other
checkboxes are not selected/deselected
thanks

Similar Messages

  • Datagrid checkbox renderer refresh?

    I am using a checkbox renderer for one of the columns in a
    flex datagrid.
    When i scroll up or down, the checkboxes i have alread
    clicked, change to different boxes (records). ????
    Not sure if this is a redraw issue. Tried to validate, but
    did not help.
    Please help.

    When we add a customized checkbox column to a datagrid in .net (windows application) , the default property allows to check or uncheck the column using a double click. On the first click it selects the column and on the second click the column is either checked or unchecked.
    To change this default property, we need to handle the click event on grid and modify the selected cell value. Here is the sample code to achieve this.
    [C#.NET VS 2003 , Code to add checkbox column to grid using table style property]
    dgItemDetails.TableStyles.Clear(); // clears the tablestyle (dgItemDetails is the name of grid)
    DataGridTableStyle dgt = new DataGridTableStyle();
    dgt.MappingName = "ItemDetails";
    DataGridBoolColumn dgbCol = new DataGridBoolColumn(); // creates the checkbox column
    dgbCol.MappingName = "Select";
    dgbCol.HeaderText = "";
    dgbCol.Width = 40;
    dgbCol.AllowNull = false;
    dgbCol.Alignment = HorizontalAlignment.Left;
    dgt.GridColumnStyles.Add(dgbCol);
    dgItemDetails.TableStyles.Add(dgt); // add
    Eliza

  • Checkbox renderer problem

    Hi all,
    I have a checkbox renderer in datagrid .The dataprovider does
    not have the selected property of the checkbox.
    how do i retain the selection of the checkbox,when i scroll
    the datagrid?
    please help.
    Thanks

    thank u very much..
    in set data method,i added the following
    override public function set data(value:Object):void{
    if(value != null){
    super.data = value;
    if((data.chkselected==null) ||
    (data.chkselected=="undefined")){
    data.chkselected = false;
    this.selected = data.chkselected;
    this works when i change checkbox selection in each row..
    i have another problem..can u please help me in solving this
    i have a checkbox as header renderer..
    On click, it is selectiing/deselecting only the checkboxes of
    rows which are visible and when i scroll the datagrid,other
    checkboxes are not selected/deselected
    thanks

  • COMBOBOX & CHECKBOX RENDERER IN JTABLE

    Hi,
    I created JXTable by using swingx palette in Netbeans IDE. In two columns of my table, for each row I want to put checkboxes and comboboxes. I searched the ways on internet and I finalise my code. However, because I used cell editor, I just see my checkboxes and comboboxes when I enter a specific cell. I read all tutorials but unfortunately I cannot learn how to use renderer to show comboboxes and checkboxes all the time. In below you could check my code and if possible please teach how to use renderers and try to give feedback to my code by fixing it. Thank you.
    *(P.S Please don't send any web site for tutorial, i searched almost all of them; but I can't understand the logic of it.)*
    // SET UP THE COMBO BOX
    public void setUpOverwriteValueColumn(JXTable table, TableColumn overwriteValCol) {
    valueCombo = new JComboBox();
    Field field = new Field();
    ArrayList values = new ArrayList();
    values = field.getValues();
    for(String a:values){
    valueCombo.addItem(a);
    overwriteValCol.setCellEditor(new DefaultCellEditor(valueCombo));
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    overwriteValCol.setCellRenderer(renderer);
    // SET UP THE CHECK BOX
    public void setUpOverwriteColumn(JXTable table, TableColumn overwriteCol) {
    valueChk = new JCheckBox();
    overwriteCol.setCellEditor(new DefaultCellEditor(valueChk));
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for check box");
    overwriteCol.setCellRenderer(renderer);
    setUpOverwriteColumn(monitorTable, monitorTable.getColumnModel().getColumn(3)); //add checkbox to 3rd column
    setUpOverwriteValueColumn(monitorTable, monitorTable.getColumnModel().getColumn(4)); //add combobox to 4th column

    Finally I can add renderers. But, now I have different question. When user clicks on the checkbox I want to enable the combo box. I mean if user clicks the checkbox in row 3; only the combo box which placed in row 3 should be enabled; other combos in other rows should not be enabled. Please help if you know the answer. Here is my code:
    public class ComboBoxRenderer extends JComboBox implements TableCellRenderer{
        public ComboBoxRenderer(Vector items) {
            super(items);
            setOpaque(false);
        public Component getTableCellRendererComponent(
                                                    JTable table,
                                                    Object value,
                                                    boolean isSelected,
                                                    boolean hasFocus,
                                                    int row,
                                                    int column){
            if (isSelected && !hasFocus){
                setBackground(table.getSelectionBackground());
                setForeground(table.getSelectionForeground());
            }else{
                setBackground(table.getBackground());
                setForeground(table.getForeground());
              setSelectedItem(value);
            return this;
    public class CheckBoxRenderer extends JCheckBox implements TableCellRenderer
      public CheckBoxRenderer() {
        setOpaque(false);
        setHorizontalAlignment(CENTER);
        setVerticalAlignment(CENTER);
      public Component getTableCellRendererComponent(
                                                        JTable table,
                                                        Object value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int row,
                                                        int column) {
        if (value != null) {
          this.setSelected( ( (Boolean) value).booleanValue());
        return this;
    }To show:
    public void setUpOverwriteValueColumn(JXTable table,
                                     TableColumn overwriteValCol) {
            Vector v = new Vector();
            Field field = new Field();
                ArrayList <String> values = new ArrayList<String>();
                values = field.getValues();
                for(String a:values){
                    v.addElement(a);
                ComboBoxRenderer renderer = new ComboBoxRenderer(v);
                overwriteValCol.setCellRenderer(renderer);
        // SET UP THE CHECK BOX
        public void setUpOverwriteColumn(JXTable table, TableColumn overwriteCol) {
                CheckBoxRenderer renderer = new CheckBoxRenderer();
                overwriteCol.setCellRenderer(renderer);
        }Edited by: duygu_simsek on Jun 18, 2009 11:27 AM

  • Datagrid checkbox renderer

    Hi all,
    I have a datagrid with checkbox as item renderers and
    checkbox as header renderer in one of its columns.
    I created a custom datagrid column extending from datagrid
    column.
    The visible property of checkbox in a row is based on a
    condition.
    All works fine if there are only 7 rows in a datagrid,i get
    three rows with checkbox and the other without checkbox.
    but,if i have more than 7 rows(with vertical scrollbar) i see
    all the checkboxes visible which should not happen.
    Thanks

    thanks for the reply sreenivas
    but i have already done that..
    here is my set data method
    override public function set data(value:Object):void{
    if(value != null){
    super.data = value;
    checkDelPermission(null);
    public function checkDelPermission(event:FlexEvent =
    null):void{
    var checkpermissioninstance:CheckPermission = new
    CheckPermission();
    checkpermissioninstance.permissions = [8];
    if(data.hasOwnProperty("permission")){
    checkpermissioninstance.permBit = data.permission;
    var delpermission:ArrayCollection =
    checkpermissioninstance.getPermissions()
    if(delpermission!=null){
    if(delpermission[0]==true){
    this.visible = true;
    else{
    this.visible=false
    else{
    this.visible = false;
    MittoApp.logMessage("permission"+data.permission +" and
    visible=="+this.visible);
    the message is always printed with the correct values but the
    display is not.
    Thanku

  • Checkbox rendere in datagrid

    Hi all,
    I have a datagrid with checkbox as renderer.
    after selecting few checkboxes,if i scroll the datagrid
    checkboxes are selected at random.
    my renderer code is attached..
    thanks

    Hi karnatis,
    Just like Alex told you, we can do it easily by
    for (var i:int = 0; i < dg.selectedItems.length; i++) {   
         Alert.show(dg.selectedItems[i].lastName);
    dg.selectedItems  -> contains all checked items
    dg.selectedItem    -> contains last checked item
    Hope this help!

  • Datagrid and checkbox renderer

    I'm looking to have a datagrid have a dataprovider from a coldfusion remote object in which i want to save a boolean value for checkboxes. i want the user to be able to select and deselect checked items and submit to a back end DB where their changes are saved.
    Then on load I want the checkbox value to be selected or deselected based on their previously saved prefs. Checkbox item renderers are a re-occuring problem for me. There seems to be so many ways to implement them and so far using online examples they don't show how to save results to a DB and reload them based on a DB. please help
    code i'm currently trying to use (where ITEM_TYPE is a DB value of true or false) and the getCheckList.lastResult is made up of 7 rows with ITEM_TYPE and DESCRIPTION (the checkbox description for the user):
    <mx:DataGrid id="myDG" dataProvider="
    {parentApplication.ATService.getCheckList.lastResult}" variableRowHeight="
    true" width="
    500" height="250" editable="
    true">
    <mx:columns>
    <mx:DataGridColumn textAlign="center" width="25" dataField="ITEM_TYPE" itemRenderer="
    mx.controls.CheckBox" rendererIsEditor="
    true"editorDataField="
    selected"/>
    <mx:DataGridColumn dataField="DESCRIPTION" />
    </mx:columns >
    </mx:DataGrid>

    I tried that Blog. It doesn't show how to preload from a database the checked or unchecked values. I did figure it out on my own though after some hard work. Using the <mx:Component> tag is nice... but i found it can't reference anything in the component its in b/c anything under <mx:Componenet> is not of the same class. trick here is to add the parentDocument. prefix and you call anything you want. also found that a DB string value (or varchar) of "true" or "false" is not recognized as boolean by flex. So to check or uncheck based on a DB result set from a CF componenet you need to actually check the value. I've attached my sample code for anyone else having trouble with this:
    <mx:DataGrid id="chkListDG" dataProvider="{parentApplication.ATService.getCheckList.lastResult}"width="
    100%" height="100%">
    <mx:columns>
    <mx:DataGridColumn textAlign="center" headerText="" dataField="CHKLIST_ID" width="30">
    <mx:itemRenderer>
    <mx:Component>
    <mx:CheckBox selected="{data.CHK_STATUS == 'true'}" click="dbChange()">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert; 
    private function dbChange():void{ 
    if (parentDocument.chkListDG.selectedItem.CHK_STATUS == 'false'){parentDocument.chkListDG.selectedItem.CHK_STATUS =
    'true'}
    else{parentDocument.chkListDG.selectedItem.CHK_STATUS =
    'false'};
    parentApplication.ATService.chkListSave(parentDocument.chkListDG.selectedItem.CHKLIST_ID,p arentDocument.chkListDG.selectedItem.CHK_STATUS);
    ]]>
    </mx:Script>
     </mx:CheckBox>  
    </mx:Component>  
    </mx:itemRenderer>
     </mx:DataGridColumn>
     <mx:DataGridColumn headerText="Description" dataField="DESCRIPTION"/>
     <mx:DataGridColumn headerText="Value" dataField="CHK_STATUS"/>
     </mx:columns>  
    </mx:DataGrid>

  • Custom Item Renderer Issue for List

    Hi,
    I have a List that uses a custom renderer that contains a
    combo box and a checkbox.
    If i define the data provider inline in MXML both the
    combobox and the checkbox render values correctly.
    However, if I switch the dataprovider to an AS 3.0
    ArrayCollection using same name/value pairs, the checkbox renders
    properly but the combo box doesn't show text values. What is weird
    is that if I trace the data, the value is accessible but it won't
    show in combo.text of control.
    Any ideas?

    The creationComplete event is called ONCE and that's it. But
    each time an itemRenderer is recycled it will have its data
    property reset with new a new record from the dataProvider. Thus
    overriding the set data function lets you inspect the data and do
    what you want with it.
    Data binding in MXML <mx:Image source="{data.image}" />
    is set up by the Flex compiler. When the data property is reset it
    will trigger the data binding notifications. The Flex
    compiler-generated code will intercept that and update the Image
    source property.
    If you use MXML, then use data binding. If you write your
    itemRenderer in ActionScript, override the set data
    function.

  • Datagrid itemRenderer checkbox

    Hi,
    I have datagrid control in my application and I use itemRenderer to render some data received from webservice. Works just fine but I would like to disable changing state of checkbox. I am using checkbox renderer just to show data more user friendly and not that users can check and uncheck it. So how can I disable checking and unchecking (by user click interaction) my checkbox in datagrid?
    I my example column with dataField "IsAlive" is the one rendered by CheckBox component.
    <mx:DataGrid id="lstAllPushes" left="10" right="10" top="10" bottom="60">
    <mx:columns>
    <mx:DataGridColumn headerText="ID" dataField="ID"/>
    <mx:DataGridColumn headerText="Start date" dataField="DateInserted"/>
    <mx:DataGridColumn headerText="Expiration date" dataField="DateExpiration"/>
    <mx:DataGridColumn headerText="Alive" dataField="IsAlive" itemRenderer="mx.controls.CheckBox"/>
    </mx:columns>
    </mx:DataGrid>
    Thx in advance.

    Try this:
    <mx:DataGridColumn headerText="Alive" dataField="IsAlive" >
         <mx:itemRenderer>
              <mx:Component>
                   <mx:CheckBox enabled="false"/>
              </mx:Component>
         </mx:itemRenderer>
    </mx:DataGridColumn>

  • Checkbox with JTree

    hai,
    i added checkbox to each tree node and my coding is
    import java.awt.BasicStroke;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.ComponentOrientation;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.GridLayout;
    import java.awt.Insets;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import java.awt.event.InputEvent;
    import java.awt.event.KeyEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import java.util.Arrays;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.Set;
    import javax.swing.AbstractAction;
    import javax.swing.AbstractButton;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTree;
    import javax.swing.KeyStroke;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.TreeCellRenderer;
    import javax.swing.tree.TreePath;
    /** Provides checkbox-based selection of tree nodes. Override the protected
    * methods to adapt this renderer's behavior to your local tree table flavor.
    * No change listener notifications are provided.
    public class CheckBoxTreeCellRenderer implements TreeCellRenderer {
    public static final int UNSELECTABLE = 0;
    public static final int FULLSELECTED = 1;
    public static final int NOTSELECTED = 2;
    public static final int PARTIALSELECTED = 3;
    private TreeCellRenderer renderer;
    public static JCheckBox checkBox;
    private Point mouseLocation;
    private int mouseRow = -1;
    private int pressedRow = -1;
    private boolean mouseInCheck;
    private int state = NOTSELECTED;
    private Set checkedPaths;
    private JTree tree;
    private MouseHandler handler;
    /** Create a per-tree instance of the checkbox renderer. */
    public CheckBoxTreeCellRenderer(JTree tree, TreeCellRenderer original) {
    this.tree = tree;
    this.renderer = original;
    checkedPaths = new HashSet();
    checkBox = new JCheckBox();
    checkBox.setOpaque(false);
    System.out.println(checkBox.isSelected());
    checkBox.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
              trace(checkBox);
    // ActionListener actionListener = new ActionListener() {
    // public void actionPerformed(ActionEvent actionEvent) {
    // AbstractButton abstractButton = (AbstractButton) actionEvent.getSource();
    // boolean selected = abstractButton.getModel().isSelected();
    // System.out.println(selected);
    // // abstractButton.setText(newLabel);
    // checkBox.addActionListener(new ActionListener(){
    //               public void actionPerformed(ActionEvent actionEvent) {
    //                    Checkbox cb = actionEvent.getSource();
    //     boolean selected = abstractButton.getModel().isSelected();
    //     System.out.println(selected);
    checkBox.setSize(checkBox.getPreferredSize());
    private static void trace(JCheckBox cb) {
         if (cb.isSelected())
              System.out.println(cb.getText()+" is " + cb.isSelected());
         else
              System.out.println(cb.getText()+" is " + cb.isSelected());
    protected void installMouseHandler() {
    if (handler == null) {
    handler = new MouseHandler();
    addMouseHandler(handler);
    protected void addMouseHandler(MouseHandler handler) {
    tree.addMouseListener(handler);
    tree.addMouseMotionListener(handler);
    private void updateMouseLocation(Point newLoc) {
    if (mouseRow != -1) {
    repaint(mouseRow);
    mouseLocation = newLoc;
    if (mouseLocation != null) {
    mouseRow = getRow(newLoc);
    repaint(mouseRow);
    else {
    mouseRow = -1;
    if (mouseRow != -1 && mouseLocation != null) {
    Point mouseLoc = new Point(mouseLocation);
    Rectangle r = getRowBounds(mouseRow);
    if (r != null)
    mouseLoc.x -= r.x;
    mouseInCheck = isInCheckBox(mouseLoc);
    else {
    mouseInCheck = false;
    protected int getRow(Point p) {
    return tree.getRowForLocation(p.x, p.y);
    protected Rectangle getRowBounds(int row) {
    return tree.getRowBounds(row);
    protected TreePath getPathForRow(int row) {
    return tree.getPathForRow(row);
    protected int getRowForPath(TreePath path) {
    return tree.getRowForPath(path);
    public void repaint(Rectangle r) {
    tree.repaint(r);
    public void repaint() {
    tree.repaint();
    private void repaint(int row) {
    Rectangle r = getRowBounds(row);
    if (r != null)
    repaint(r);
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    installMouseHandler();
    TreePath path = getPathForRow(row);
    state = UNSELECTABLE;
    if (path != null) {
    if (isChecked(path)) {
    state = FULLSELECTED;
    else if (isPartiallyChecked(path)) {
    state = PARTIALSELECTED;
    else if (isSelectable(path)) {
    state = NOTSELECTED;
    checkBox.setSelected(state == FULLSELECTED);
    checkBox.getModel().setArmed(mouseRow == row && pressedRow == row && mouseInCheck);
    checkBox.getModel().setPressed(pressedRow == row && mouseInCheck);
    checkBox.getModel().setRollover(mouseRow == row && mouseInCheck);
    Component c = renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    checkBox.setForeground(c.getForeground());
    if (c instanceof JLabel) {
    JLabel label = (JLabel)c;
    // Augment the icon to include the checkbox
    Icon customOpenIcon = new ImageIcon("browse.gif");
    label.setIcon(new CompoundIcon(label.getIcon()));
    return c;
    private boolean isInCheckBox(Point where) {
    Insets insets = tree.getInsets();
    int right = checkBox.getWidth();
    int left = 0;
    if (insets != null) {
    left += insets.left;
    right += insets.left;
    return where.x >= left && where.x < right;
    public boolean isExplicitlyChecked(TreePath path) {
    return checkedPaths.contains(path);
    /** Returns whether selecting the given path is allowed. The default
    * returns true. You should return false if the given path represents
    * a placeholder for a node that has not yet loaded, or anything else
    * that doesn't represent a normal, operable object in the tree.
    public boolean isSelectable(TreePath path) {
    return true;
    /** Returns whether the given path is currently checked. */
    public boolean isChecked(TreePath path) {
    if (isExplicitlyChecked(path)) {
    return true;
    else {
    if (path.getParentPath() != null) {
    return isChecked(path.getParentPath());
    else {
    return false;
    public boolean isPartiallyChecked(TreePath path) {
    Object node = path.getLastPathComponent();
    for (int i = 0; i < tree.getModel().getChildCount(node); i++) {
    Object child = tree.getModel().getChild(node, i);
    TreePath childPath = path.pathByAddingChild(child);
    if (isChecked(childPath) || isPartiallyChecked(childPath)) {
    return true;
    return false;
    private boolean isFullyChecked(TreePath parent) {
    Object node = parent.getLastPathComponent();
    for (int i = 0; i < tree.getModel().getChildCount(node); i++) {
    Object child = tree.getModel().getChild(node, i);
    TreePath childPath = parent.pathByAddingChild(child);
    if (!isExplicitlyChecked(childPath)) {
    return false;
    return true;
    public void toggleChecked(int row) {
    TreePath path = getPathForRow(row);
    boolean isChecked = isChecked(path);
    removeDescendants(path);
    if (!isChecked) {
    checkedPaths.add(path);
    setParent(path);
    repaint();
    private void setParent(TreePath path) {
    TreePath parent = path.getParentPath();
    if (parent != null) {
    if (isFullyChecked(parent)) {
    removeChildren(parent);
    checkedPaths.add(parent);
    } else {
    if (isChecked(parent)) {
    checkedPaths.remove(parent);
    addChildren(parent);
    checkedPaths.remove(path);
    setParent(parent);
    private void addChildren(TreePath parent) {
    Object node = parent.getLastPathComponent();
    for (int i = 0; i < tree.getModel().getChildCount(node); i++) {
    Object child = tree.getModel().getChild(node, i);
    TreePath path = parent.pathByAddingChild(child);
    checkedPaths.add(path);
    private void removeChildren(TreePath parent) {
    for (Iterator i = checkedPaths.iterator(); i.hasNext();) {
    TreePath p = (TreePath) i.next();
    if (p.getParentPath() != null && parent.equals(p.getParentPath())) {
    i.remove();
    private void removeDescendants(TreePath ancestor) {
    for (Iterator i = checkedPaths.iterator(); i.hasNext();) {
    TreePath path = (TreePath) i.next();
    if (ancestor.isDescendant(path)) {
    i.remove();
    /** Returns all checked rows. */
    public int[] getCheckedRows() {
    TreePath[] paths = getCheckedPaths();
    int[] rows = new int[checkedPaths.size()];
    for (int i = 0; i < checkedPaths.size(); i++) {
    rows[i] = getRowForPath(paths);
    Arrays.sort(rows);
    return rows;
    /** Returns all checked paths. */
    public TreePath[] getCheckedPaths() {
    return (TreePath[]) checkedPaths.toArray(new TreePath[checkedPaths.size()]);
    protected class MouseHandler extends MouseAdapter implements MouseMotionListener {
    public void mouseEntered(MouseEvent e) {
    updateMouseLocation(e.getPoint());
    public void mouseExited(MouseEvent e) {
    updateMouseLocation(null);
    public void mouseMoved(MouseEvent e) {
    updateMouseLocation(e.getPoint());
    public void mouseDragged(MouseEvent e) {
    updateMouseLocation(e.getPoint());
    public void mousePressed(MouseEvent e) {
    pressedRow = e.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK
    ? getRow(e.getPoint()) : -1;
    updateMouseLocation(e.getPoint());
    public void mouseReleased(MouseEvent e) {
    if (pressedRow != -1) {
    int row = getRow(e.getPoint());
    if (row == pressedRow) {
    Point p = e.getPoint();
    Rectangle r = getRowBounds(row);
    p.x -= r.x;
    if (isInCheckBox(p)) {
    toggleChecked(row);
    pressedRow = -1;
    updateMouseLocation(e.getPoint());
    public void mouseClicked(MouseEvent e){
         if(checkBox.isSelected()){
              System.out.println(checkBox.getName());
    /** Combine a JCheckBox's checkbox with another icon. */
    private final class CompoundIcon implements Icon {
    private final Icon icon;
    private final int w;
    private final int h;
    private CompoundIcon(Icon icon) {
    if (icon == null) {
    icon = new Icon() {
    public int getIconHeight() { return 0; }
    public int getIconWidth() { return 0; }
    public void paintIcon(Component c, Graphics g, int x, int y) { }
    this.icon = icon;
    this.w = icon.getIconWidth();
    this.h = icon.getIconHeight();
    public int getIconWidth() {
    return checkBox.getPreferredSize().width + w;
    public int getIconHeight() {
    return Math.max(checkBox.getPreferredSize().height, h);
    public void paintIcon(Component c, Graphics g, int x, int y) {
    if (c.getComponentOrientation().isLeftToRight()) {
    int xoffset = checkBox.getPreferredSize().width;
    int yoffset = (getIconHeight()-icon.getIconHeight())/2;
    icon.paintIcon(c, g, x + xoffset, y + yoffset);
    if (state != UNSELECTABLE) {
    paintCheckBox(g, x, y);
    else {
    int yoffset = (getIconHeight()-icon.getIconHeight())/2;
    icon.paintIcon(c, g, x, y + yoffset);
    if (state != UNSELECTABLE) {
    paintCheckBox(g, x + icon.getIconWidth(), y);
    private void paintCheckBox(Graphics g, int x, int y) {
    int yoffset;
    boolean db = checkBox.isDoubleBuffered();
    checkBox.setDoubleBuffered(false);
    try {
    yoffset = (getIconHeight()-checkBox.getPreferredSize().height)/2;
    g = g.create(x, y+yoffset, getIconWidth(), getIconHeight());
    checkBox.paint(g);
    if (state == PARTIALSELECTED) {
    final int WIDTH = 2;
    g.setColor(UIManager.getColor("CheckBox.foreground"));
    Graphics2D g2d = (Graphics2D)g;
    g2d.setStroke(new BasicStroke(WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int w = checkBox.getWidth();
    int h = checkBox.getHeight();
    g.drawLine(w/4+2, h/2-WIDTH/2+1, w/4+w/2-3, h/2-WIDTH/2+1);
    g.dispose();
    finally {
    checkBox.setDoubleBuffered(db);
    private static String createText(TreePath[] paths) {
    if (paths.length == 0) {
    return "Nothing checked";
    String checked = "Checked:\n";
    for (int i=0;i < paths.length;i++) {
    checked += paths[i] + "\n";
    return checked;
    public static void main(String[] args) {
    try {
    final String SWITCH = "toggle-componentOrientation";
    try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              } catch (ClassNotFoundException e1) {
                   e1.printStackTrace();
              } catch (InstantiationException e1) {
                   e1.printStackTrace();
              } catch (IllegalAccessException e1) {
                   e1.printStackTrace();
              } catch (UnsupportedLookAndFeelException e1) {
                   e1.printStackTrace();
    JFrame frame = new JFrame("Tree with Check Boxes");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final DefaultMutableTreeNode a = new DefaultMutableTreeNode("Node 1");
    for(int i =0 ; i<3; i++ ){
         DefaultMutableTreeNode b = new DefaultMutableTreeNode("ChildNode "+i);
         a.add(b);
    DefaultMutableTreeNode e = new DefaultMutableTreeNode("Node 2");
    for(int i =0 ; i<3; i++ ){
         DefaultMutableTreeNode f = new DefaultMutableTreeNode("ChildNode "+i);
         e.add(f);
    DefaultMutableTreeNode al = new DefaultMutableTreeNode("Sample");
    al.add(a);
    al.add(e);
    final JTree tree = new JTree(al);
    final CheckBoxTreeCellRenderer r =
    new CheckBoxTreeCellRenderer(tree, tree.getCellRenderer());
    tree.setCellRenderer(r);
    int rc = tree.getRowCount();
    tree.getActionMap().put(SWITCH, new AbstractAction(SWITCH) {
    public void actionPerformed(ActionEvent e) {
    ComponentOrientation o = tree.getComponentOrientation();
    if (o.isLeftToRight()) {
    o = ComponentOrientation.RIGHT_TO_LEFT;
    else {
    o = ComponentOrientation.LEFT_TO_RIGHT;
    tree.setComponentOrientation(o);
    tree.repaint();
    int mask = InputEvent.SHIFT_MASK|Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    tree.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_O, mask), SWITCH);
    final JTextArea text = new JTextArea(createText(r.getCheckedPaths()));
    text.setPreferredSize(new Dimension(200, 100));
    tree.addMouseListener(new MouseAdapter() {
    public void mouseReleased(MouseEvent e) {
    // Invoke later to ensure all mouse handling is completed
    SwingUtilities.invokeLater(new Runnable() { public void run() {
    text.setText(createText(r.getCheckedPaths()));
    JScrollPane pane = new JScrollPane(tree);
    frame.getContentPane().add(pane);
    // frame.getContentPane().add(new JScrollPane(text), BorderLayout.SOUTH);
    frame.pack();
    frame.setSize(600,400);
    frame.setVisible(true);
    catch(Exception e) {
    e.printStackTrace();
    System.exit(1);
    now i need to get nodes names which has been selected, how can i do this
    can anyone help me ...
    regards,
    shobi

    Also, use code tags and post a SSCCE -- I'm sure more of your posted code is irrelevant to your question and few people are going to look at a code listing that long.
    [http://mindprod.com/jgloss/sscce.html]

  • Checked CheckBoxes moving around in DataGrid

    I have a DataGrid and I use a CheckBox as a custom
    ItemRenderer/ItemEditor. I make the CheckBox a custom renderer so I
    can disable it in certain rows depending on the value of the data
    in that row.
    When I select a few check boxes in the DataGrid and then
    scroll through the DataGrid other CheckBoxes that I did not check
    will show a check. Even some of the disabled CheckBoxes will show a
    check mark.
    The data binding works properly no matter how screwed up the
    rendering is. Only the CheckBoxes that I actually check show up as
    checked in the data. It is just the rendering that is screwed up.
    Here is my code from the DataGrid and my custom renderer:
    <mx:DataGridColumn
    id="distributeCB"
    rendererIsEditor="true"
    headerText="Distribute"
    width="70"
    dataField="distribute"
    editorDataField="selected"
    itemRenderer="com.avaya.im.decm.branches.CheckBoxItemRenderer"
    />
    <?xml version="1.0" encoding="utf-8"?>
    <mx:CheckBox
    xmlns:mx="
    http://www.adobe.com/2006/mxml"
    enabled="{data.status==notDistributedStr}"
    change="data.distribute=selected" >
    <mx:Script>
    <![CDATA[
    // Must match BranchCoveragePathTemplates.NOT_DISTRIBUTEDD
    public const notDistributedStr:String = "Not Distributed";
    ]]>
    </mx:Script>
    </mx:CheckBox>
    Has anyone seen this and solved it?
    Thanks.

    The list components re-use the item renderers when you
    scroll. This means that the checkbox state must be driven by the
    dataProvider.
    Your checkBox renderer must override the set Data method and
    set the selected property based on a value in the dataProvider
    item.
    When the user clicks the checkbox, the renderer must updte
    the dataProvider item with the value.
    Here is a full example:
    http://www.cflex.net/showfiledetails.cfm?ChannelID=1&Object=File&objectID=559
    Tracy

  • CHECKBOX is showing as Text box

    Hello Friends,
    We upgraded system from 4.7 to ECC 6.0
    In 4.7, SAP is displaying checkbox as Select Box (Tick)  , But in ECC is displaying as text box.
    Declaration in both the systems is
    PARAMETERS:   TEST  TYPE CHECKBOX.
    Please let me know that do i need to set any options to display as Checkbox in ECC.
    or do i need to chage code as
    PARAMETERS: TEST  AS CHECKBOX.
    Thanks & Regards
    Dinesh

    Hi.  I don't have a 4.7 system in front of me at the moment, but in NW 7.0(ECC), you must use the AS CHECKBOX, and not the TYPE CHECKBOX.
    When you say..
    PARAMETERS: p_test1 type checkbox.
    You are merely assigning a type here.  And since there is a data element called CHECKBOX, the syntax checker will allow this.  The CHECKBOX data element is nothing more thann a character field with a length of one.
    Now if you specify this.
    PARAMETERS: p_test2 AS checkbox.
    You are telling the compiler something else, you are saying that you want a "checkbox" rendered in the screen. and similarly this field will be a character field with length of 1.
    Cheers,
    Rich

  • Label for htmldb_item.checkbox

    Is there a way to put a display label for checkboxes rendered with htmldb_item.checkbox?
    I know it doesnt make much sense to put a label on every row next to each checkbox on a report region, but just wanted to know if it was possible.
    Thanks

    Thanks, that works!
    I just tested this out on the hosted site (24317:4)
    What does the
    onMouseOver="row_mouse_over1517788416209474431(this, 1)"
    stuff in the table do? I am pretty sure I dont get that on my site. Is it related to the theme/template? it doesnt seem to do anything
    Thanks

  • Cell rendering in JTable

    Can someone show me how to render the cells of a table column as a combo box and the cells of another table column as a check box.
    thx.

    Hi,
    You can easily get the checkbox as the renderer by implementing the getColumnClass(int columnIndex). But the catch is that your checkbox-column should return Boolean as its class. Check for that. That can only be the problem. Otherwise, it should work fine.
    public Class getColumnClass(int column) {
        switch(column) {
            case 1 :
                /* Assume that this is the column for which the checkbox
                 * rendering has to take place.
                return Boolean.class;
                break;
            case 2 :
                //Return the datatype of this column, say it is a Number
                return Number.class;
                break;
            //Your other cases would go here
            default :
                return String.class;
                break;
    }I hope that your problem is solved now. If not, there is another way by which you can explicitlt set the renderer of your column. In this case, there is no need to implement the getColumnClass() method. Here is the CheckBoxCellRender class...
    class CheckBoxCellRenderer extends JCheckBox implements TableCellRenderer
        public CheckBoxCellRenderer() {
            setHorizontalAlignment(JLabel.CENTER);
        }//constructor
        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());
            setSelected((value != null && ((Boolean)value).booleanValue()));
            return this;
        }//getTableCellRendererComponent
    }Put this class as an inner class somewhere in your code, and then explicitly set this class as the column's default renderer. Here is how you can do it.
    myTable.getColumn("myCheckboxColumn").setCellRenderer(new CheckBoxCellRenderer());

  • Column header sorting: Checkboxes

    Column header sorting doesnt seem to work like one would expect when the column is a checkbox rendered using htmldb_item.checkbox().
    If I have a some boxes checked, some unchecked on a page and I click on the column header, I would expect all the checked and unchecked boxes to show up together. But they dont. Does the HTML for the checkbox interfere with the sorting? Is there a way to make it sort what you see on screen?
    Thanks

    Vikas,
    What you get when using htmldb_item calls in your query are varchar2 columns. So it’s ordered by the resulting strings, including all HTML tags that are rendered by that procedure. You might be able to do what you are describing by using Tyler’s sorting hack somehow:
    Dynamic Selection of Report Column Format
    Regards,
    Marc

Maybe you are looking for

  • WM-production order-need change the open quantity in Transfer order

    Hi,    I created the production order (order quantity 1000).  i did material staging and generated TR. .    But i need to change the open quantity in transfer order . i need to create the partial Transfer order     against TR..    KINDLY SUGGEST ME  

  • How can i format my mac book pro v10.6.8

    hi i m using macbook pro v10.6.8  its too slow i just wanna format it and dont know how to format it so please help me to format it as soon as posibble please

  • Says it is paused when I try to import.

    When I try to import from my camera, iMovie says the camera is paused even though it is playing on screen and in my camera. Any thoughts?

  • VM Creation fails on cloud works on host

    When I create a vm and choose to deploy it to my cloud it fails I get the error that I listed in this post http://social.technet.microsoft.com/Forums/systemcenter/en-US/8692629f-250e-47c0-b7e7-3d709402e3e3/task-ids-in-vmm-2012?forum=virtualmachineman

  • Namespace /CRYSTAL/ missing

    hello, I'm trying to install the crystal reports 2008 but when importing the requests the system says that there is a problem with the namespace /CRYSTAL/ This namespace doesn't exist in my system (abap netweaver trial). any idea on how to create thi