Checkbox in table cell won't uncheck

Hey all,
Can someone help with this please. I am using a table model where the second column is Boolean. The table correctly renders this as a checkbox (I'm not using a custom renderer). The checkbox works ok except that you can't uncheck it. You can change which row is selected, but clicking twice on the same cell has no effect - it just stays checked.
Thanks in advance for any help.

here I am giving one example. Can u check this. In this eg, I gave check box in 3rd column(column no starting from 0).
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.awt.*;
public class Class1 extends JFrame {
JScrollPane jScrollPane1 = new JScrollPane();
public Class1() {
super();
try {          
     MyTableModel model = new MyTableModel();     JTable editableTable1 = new JTable(model);     
     DefaultTableModel tblmdl = (DefaultTableModel) editableTable1.getModel();
     tblmdl.setRowCount(3);     
     tblmdl.setColumnCount(3);     
               editableTable1.setCellSelectionEnabled(true);
     this.getContentPane().setLayout(null);
               jScrollPane1.setBounds(new Rectangle(25, 19, 330, 180));
     this.getContentPane().add(jScrollPane1, null);
               jScrollPane1.getViewport().add(editableTable1, null);
     addWindowListener(new WindowAdapter() {
     public void windowClosing(WindowEvent we) {
          System.exit(0);
} catch(Exception e) {
     System.out.println("Exception in Class1:"+e);
class MyTableModel extends DefaultTableModel {
     MyTableModel() {
     public Class getColumnClass(int c) {
     if(c == 2) {
     return Boolean.class;
     } else {
     return String.class;
public static void main(String[] args) {
Class1 class1 = new Class1();
class1.setSize(400, 400);
class1.setVisible(true);
}

Similar Messages

  • Problem with CheckBox as table cell renderer

    i m making a JTable having three columns.
    i m also making a cellRenderer of my own MyRenderer
    extending Jcheckbox and implementing TableCellRenderer
    now i m setting MyRenderer as renderer for third column in my table and
    DefaultCellEditor with jcheckbox as parameter as cell editor for this column
    the code is like this--------------------
    ****making of JTable****
    table= new JTable(3,3);
    JScrollPane scrollPane = new JScrollPane(table);
    TableColumn tableColumn = table.getColumn("Male"); // let us suppose that this gives third column
    tableColumn.setCellRenderer(new MyRenderer ());
    tableColumn.setCellEditor(new DefaultCellEditor(new JCheckBox()));
    *****The classs implementing TableCellRenderer is given below******
    class MyRenderer extends JCheckBox implements TableCellRenderer{
    public MyRenderer(){
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column){
    if(value != null){
    Boolean booleanValue = (Boolean)value;
    setSelected(booleanValue.booleanValue());
    return this;
    ***********************************Problem****************************
    The problem is that when we click on the cell of that column first time,
    all the cells are selected.
    I don't want to use getColumnClass() method for this problem .
    If possible , please give some other solution.
    what is the problem behind this,If anybody can help us.
    Thanks in advance.

    I think the problem is, when the value is null the checkbox return with the selected state, b'coz u r
    returning the checkbox (as it is). so pl'z try with below code (ADDED).
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column){
    if(value != null){
    Boolean booleanValue = (Boolean)value;
    setSelected(booleanValue.booleanValue());
    else /// ADDED
    setSelected(false);/// ADDED
    return this;
    Nediaph.

  • SOLVED: Editing a table cell won't update corresponding ViewObject

    Hi,
    I'm asking for your help.
    I want to update a ViewObject with userinput from jTableCells. The JTable that has been constructed by JDev based on this ViewObject. The attributes of this ViewObject are the result of a SQL query using the NVL() function.
    The Problem is that changing cell values does not update the ViewObject. I guess NVL() causes this. Right?
    As a solution I'd like to add a TableModelListener to the table and take care that changes to cell-data find their way into the right ViewObject attribute. Is this the right solution?
    How can I add a working TableModelListener?
    My try:
    jTable1.getModel().addTableModelListener(new MyTableModelListener());
    The TableModelEvent, that MyTableModelListener gets, always returns "-1" for getColumn(). Why?
    Is there another way to get the current row and column (where the cell-edit takes place)?
    I hardly know anything about ADF, panelbindings and so on, so don't back off with answers that my appear too simple or obvious to you.
    Regards, MaeSiuS
    Message was edited by:
    MaeSiuS

    Hi Frank,
    yes, it is based on EntityObjects.
    For a test, I replaced one of the NVL() based attributes with the plain attribute of the EntityObject, but that had no effect on the update disability.

  • How to use a checkbox table cell in FXML

    I've figured out how to make a column in a TableView render as a checkbox rather then just text when the UI is written in Java. Now I'm trying to figure out how to do the same thing with FXML. I've tried a couple experiments which have all failed, usually with an exception complaining that it can't coerce a table cell class type (or extension) to an interface (i.e. Callback).
    Right now I'm just trying to make one of the columns be a checkbox. I'm not trying to use any custom type. In other words, in Java I would have done the following:
    TableColumn<MyModel, Boolean> col1 = new TableColumn<MyModel, Boolean>();
    col1.setCellValueFactory(new PropertyValueFactory<MyModel, Boolean>("col1Field"));
    col1.setCellFactory(CheckBoxTableCell.forTableColumn(col1));This works when I build the UI using Java API calls. Does anyone know how to do this in FXML?

    Thank you both.
    I used Luca's suggestion as a first step.
    You'll find attached my v.i. that enables me to do what I wanted. It finally works as I expected. It would have been much simpler if my DAQ was able to measure directly a resistance!
    Loris
    Attachments:
    banc_de_test_température.vi ‏205 KB

  • Need help: checkbox or radiobutton in table cell

    So basically i am looking for code samples or links to where i can find an implementation of 2 or 3 radiobuttons or checkboxes in a table cell/column, so that for each row, i can have a selection of A, B or C for a particular string in the first column. I can create a table with one checkbox, but i cant figure out 2 or more inside the same cell.
    thanks :)

    The JTable tutorial has a section titled "Using a Combo Box as an Editor". Take a look at their example for how to do this.
    http://java.sun.com/docs/books/tutorial/uiswing/components/table.html

  • How can i uncheck a checkbox in table component on clicking a button

    In my application I have a table component that display data from the database and a submit button outside the table component, the first column in the table component is a checkbox, How can i uncheck the checkbox in the table component when the submit button is clicked?
    Thanks in advance.

    Something like this ... I THINK it will uncheck all checkboxes in table, but I'm not positive ... you can test!
    if checkbox id is checkbox1...
    <script type="text/javascript"><![CDATA[                                         
    function disableCheckbox()
    document.getElementById('form1:checkbox1').selected = false;
    }]]></script>Put above code inside of head tag in JSP View
    NEXT...
    go to Design View and select your button and go to properties section and select onClick property and insert this javascript in dialog...
    setTimeout('disableCheckbox()', 1)Now run the project when you click the button does the checkbox become unselected?
    Anyway this is where I would start...as far as selecting just the first checkbox if there is more than 1 record...I'm not sure...but I'm curious if this works.
    Jason

  • Inserting multiple checkboxes into a table cell

    Hi all, new to Livecycle so I could use a little advice.
    I'm trying to insert multiple checkboxes into a single table cell, but as far as I can tell that seems impossible as one checkbox fills the entire cell. Now how do I go about splitting the table cell into 2 rows so that I can insert both of the checkboxes?
    I've also got to add a button to create new rows for the table on click so I don't know if that will factor into the answer.
    |        Header               |           Header2             |           Header3           |
    |                                  |                                      |__________________|
    |                                  |                                      |                                    |
    I hope this crappy ascii drawing comes out right, but that's what I need to happen.
    Thanks!

    Hi Chris,
    I think this should give you what you need: Working with a Multiple Select List Item
    --Jennifer                                                                                                                                                                                                                                                                                                                                                                                                   

  • Margin and Table Cell Question

    Hi,
    The main banner at the top of each page changes it's position
    when I view it in the browser. For example, on this page it is okay
    http://www.foryourbackyard.com.au/products.htm
    Though this page the banner slips down a touch.
    http://www.foryourbackyard.com.au/sheds.htm
    Any ideas welcome.
    Also on this site the table cells seem to have a gap at the
    bottom of the roll over image.
    http://www.d-force.com.au/
    I'm not sure why.
    Thank in advance.
    Ray

    For anybody who might stumble on this in the future looking for an answer to the same or a similar question, I figured this out with the help of Andreas Kiel and Philip Buckley on the Applescript Studio mailing list. Below is the answer.
    Given a data source named "D" and table columns named "bc1" and "bc2" (both of which contain a checkbox style button cell), this is the syntax:
    tell data source "D" --to check the checkboxes
    set content of data cell "bc1" of every data row to true
    set content of data cell "bc2" of every data row to true
    end tell
    tell data source "D" --to uncheck the checkboxes
    set content of data cell "bc1" of every data row to false
    set content of data cell "bc2" of every data row to false
    end tell
    The problem I was having is that I used the name of the button cell itself in the data cell reference rather than the name of the table column.
    Hope someone finds this useful
    St!ff

  • How to prevent a JButton in a Table Cell from stretching its size.

    Hi,
    I have JButton added to a Table Cell. But the button is filled up by covering the whole area of the cell and when I go for increase the width of the Table column, the button size is also stretched up along with the column's increasing width. How can I implement a solutiong so that I have a preferred size for the button so that when I go for stretch the column, the button should retain its preferred size. That mean it should not be stretched.
    I hereby added the code for a reference,
        // ButtonEditor
        class ButtonEditor extends DefaultCellEditor {
            private static final long serialVersionUID = 42L;
             private String    label;
             private boolean   isPushed;
                    protected JButton button;
             public ButtonEditor(JCheckBox checkBox) {
                  super(checkBox);
                  button = new JButton();
                  button.setOpaque(true);
                  button.addActionListener(new ActionListener() {
                       public void actionPerformed(ActionEvent e) {
                            fireEditingStopped();
              * Override the DefaultCellEditor inbuilt method
             public Component getTableCellEditorComponent(JTable table, Object value,
                       boolean isSelected, int row, int column) {
                  if(value.equals(AdminToolsRes.resBundle.getString("nei.label.blockSync"))){
                       label = (value == null) ? "" : value.toString();
                       button.setText( label );
                       isPushed = true;
                       return button;
                  else
                       return null;
              * Stop cell editing
             public boolean stopCellEditing() {
                  isPushed = false;
                  return super.stopCellEditing();
              * call the fireEditingStopped method
             protected void fireEditingStopped() {
                  super.fireEditingStopped();
              * sets the cell editable to True
              * @return
             public boolean isCellEditable(){
                  return true;
        //ButtonRenderer
        class ButtonRenderer extends JButton implements TableCellRenderer {
            private static final long serialVersionUID = 42L;
             public ButtonRenderer() {
                  setOpaque(true);
              * Override the TableCellRenderer inbuilt method
             public Component getTableCellRendererComponent(JTable table, Object value,
                       boolean isSelected, boolean hasFocus, int row, int column) {
                  if (isSelected) {
                     setBackground(table.getSelectionBackground());
                 } else{
                     setForeground(table.getForeground());
                     setBackground(table.getBackground());
                  if(value.equals(AdminToolsRes.resBundle.getString("nei.label.blockSync"))){
                       setText( (value == null) ? "" : value.toString() );
                       return this;
                  }else{
                       JTextField txtFld = new JTextField();
                       txtFld.setBorder(null);
                       txtFld.setText((value ==null) ? "" : value.toString());
                       if(isSelected){
                            txtFld.setForeground(table.getSelectionForeground());
                            txtFld.setBackground(table.getSelectionBackground());
                       return txtFld;
        }Please help me in answering the question.
    SumodeV

    I feel, here the JPanel also might get stretched up.All renderers are sized to fill the entire area of the cell, so yes, the panel will get stretched, but the button won't. That is why the suggestion was made.
    All renderers are sized to fill the entire area of the cell.
    Not sure, but you might be able to override the JTable.prepareRenderer(...) method to reset the size of the button back to is preferred size. I have no idea how this will affect the rendering.

  • Mail.app: text in table cells in incoming formatted mail - problems replying

    MacOS 10.9.2
    mail.app  7.2, threading enabled
    Sometimes I receive a formatted email that is really difficult to reply to, when I want to intersperse my reply text among the incoming paragraphs.
    The trouble occurs when multiple incoming paragraphs are grouped. I can’t open up vertical space for my reply  text inside the groups. 
    If I click anywhere in the group, mail.app marks the group with a surrounding rounded-corner grey rectangle, with a X-in-a-circle “close icon” at the upper left corner. 
    When I look at the raw source of the incoming message, I see that the groups correspond to table cells, that is, the sending mail client enclosed the paragraphs within a <td> … </td> pair.
    The sending email client is sending me a table, for no clear reason — the group doesn’t correspond to anything obvious in the message thread.
    I’m guessing we won’t ever know why some email clients group paragraphs like this, but I’d like to do my best to adapt, so I can keep up with my incoming email. 
    Yeah, I can ask my correspondents to use a different email client, or perhaps different settings in the same client, but except for the few tekkies among my correspondents, this isn’t really practical.  I can also ask my clients to use unformatted messages, but THAT is a whole different issue, and frequently isn’t practical, either.
    My questions:
    Q1:  What’s the point of the grey rectangle and the  “close icon”?    (Is this mail.app’s way of saying, “I received this crazy formatting, almost impossible to process, so I’m making it easy for you to just delete the whole mess”?  Or what?)
    Q2:  Is there any SIMPLE way to untangle (modify or remove) these groupings within mail.app?  (I guess I can access the raw html, copy-and-paste it into another app, modify it, and paste the results back into my reply.  Yuck!)
    Q3: Am I missing a really obvious work-around or fix?
    TIA

    In your question, you indicated that you are running Firefox 8. Is that correct? It might be difficult to diagnose issues with that version because most people have moved on to Firefox 12 (plus or minus 1 version). Can you upgrade?
    It's hard to think of a reason that ordinary text or links in ordinary text would not display. For embedded images or videos, one possibility is a difference in the protocol, i.e., HTTP (not secure) versus HTTPS (secure).
    Hopefully someone else will have a better guess (or actual knowledge!).
    Regarding the blue lines in a message, that usually indicates the earlier message was forwarded a few times. I don't know whether Gmail will let you reformat that area or whether you have to clean it in another application (e.g., for plain text, in Notepad) and paste it back in.

  • Placing text beside image in a table cell?

    I'm creating business cards (using a Printworks template), and I want to place text to the right of the inserted picture.
    I've copied and pasted the jpg fine onto the left side of the cell, yet when I try to type text, the cursor only lets me begin typing at the bottom right side of the photo, not up at the top right side, where I want the info to start.
    Further, when I try to insert a Text Box into the cell, it won't go inside.
    So, my question: *How do I get image and text together inside a table cell?*

    I made an ultimate test.
    I grouped a jpeg picture and a shape in which I inserted a piece of text. You may see it on the screenshot.
    I inserting the group in the cell hoping that the group will be correctly displayed.
    Nada, only the picture appears.
    If I select the object embedded in the cell, copy it, paste it in an other location, I may ungroup it but the now separated shape no longer contains the original text
    Yvan KOENIG (VALLAURIS, France) lundi 7 juin 2010 17:55:18

  • Table cell flashing

    Hi,
    Before I start to hack away a solution that might not be fx-like, I'd like to get your expert opinion about implementing cell flashing for a table view.
    I have done this several times in Swing (using a timer, a customer renderer, switching the bg/fg colors 3 times, and firing up an even table cell update), but how do implement this feature in JavaFX?
    * The table cell renderer (override def call (...)) could be used
    * The bg/fg color switch can be done using different css styles
    * what would be the best way to implement the timer and ask the view to "repaint" a specific cell?
    Thx v much

    Below is a bit of code that does something like what you want (the port to groovy should be easy). It may need some testing/tweaking for a real scenario and I'm not sure just how many animated cells you could have going at a time before performance becomes an issue (maybe someone from the JFX team could comment on this?).
    Also, regarding the use of styles for animating the change, you should be aware of this: Removing CSS style classes?
    Basically you need to make sure your 'default' style has values set for everything your 'highlight' style messes with, otherwise the highlight won't get turned off.
    import javafx.animation.FadeTransition;
    import javafx.animation.Timeline;
    import javafx.application.Application;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.TableCell;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    import javafx.util.Duration;
    public class TestApp extends Application
        public static void main(String[] args)
            Application.launch(args);
        @Override
        public void start(Stage stage) throws Exception
            BorderPane root = new BorderPane();
            TableView<Person> table = new TableView<Person>();
            table.getItems().addAll(
                    new Person("Cathy", "Freeman"),
                    new Person("Albert", "Namatjira"),
                    new Person("Noel", "Pearson"),
                    new Person("Oodgeroo", "Nooncal")
            TableColumn<Person, String> firstNameCol = new TableColumn<Person, String>("First Name");
            firstNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("firstName")
            table.getColumns().add(firstNameCol);
            TableColumn<Person, String> lastNameCol = new TableColumn<Person, String>("Last Name");
            lastNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("lastName")
            lastNameCol.setCellFactory(new Callback<TableColumn<Person, String>, TableCell<Person, String>>()
                public TableCell<Person, String> call(TableColumn<Person, String> column)
                    final FlashingLabel label = new FlashingLabel();
                    label.setStyle("-fx-background-color: #ffaaaa");
                    TableCell<Person, String> cell = new TableCell<Person, String>()
                        protected void updateItem(String value, boolean empty)
                            super.updateItem(value, empty);
                            label.setText(value);
                            label.setVisible(!empty);
                    cell.setGraphic(label);
                    return cell;
            table.getColumns().add(lastNameCol);
            root.setCenter(table);
            Scene scene = new Scene(root, 800, 600);
            scene.getStylesheets().add("styles.css");
            stage.setScene(scene);
            stage.show();
        public class FlashingLabel extends Label
            private FadeTransition animation;
            public FlashingLabel()
                animation = new FadeTransition(Duration.millis(1000), this);
                animation.setFromValue(1.0);
                animation.setToValue(0);
                animation.setCycleCount(Timeline.INDEFINITE);
                animation.setAutoReverse(true);
                animation.play();
                visibleProperty().addListener(new ChangeListener<Boolean>()
                    public void changed(ObservableValue<? extends Boolean> source, Boolean oldValue, Boolean newValue)
                        if (newValue)
                            animation.playFromStart();
                        else
                            animation.stop();
        public class Person
            private String firstName;
            private String lastName;
            private Person(String firstName, String lastName)
                this.firstName = firstName;
                this.lastName = lastName;
            public String getFirstName()
                return firstName;
            public String getLastName()
                return lastName;
    }

  • Autofit column width to table cell content in Pages

    Hello,
    Would anyone know how to autofit the column width of a table cell in Pages '09?
    I have searched Pages Help to no avail.
    Thank you very much in advance.

    There is a checkbox in the table inspector to auto-resize to fit content. Unfortunately, that only seems to work with rows, not columns.

  • Get table cell value on click without using submit or action

    hello ,
    i am having html table containing values retrieved from database.
    i want to create table cell as a link and want to pass cell's value to the next page without using submit, radio button, checkbox.
    it is feasible in PHP and ASP but i want to solve in jsp. pls suggest the solution.
    Edited by: Avinash123 on Dec 16, 2008 2:58 AM

    Here is sample code
    <script type="text/javascript">
    function callForm(data)
    frm.action="anotherjsp.jsp?value="+data;
    frm.submit();
    </script>
    <form name="frm" action="">
    <table id="test" border='1'>
    <tr >
    <td onclick="callForm('Data1')" > Data1 </td>
    <td onclick="callForm('Data2')" > Data2 </td>
    <td onclick="callForm('Data3')" > Data3 </td>
    <td onclick="callForm('Data4')" > Data4 </td>
    </tr>
    </table>
    </form>

  • Automatically Sizing Table Cell Width Using CSS

    How can I get my CSS sheet to automatically size the width of
    the table cells where text is located?
    Example
    Page

    quote:
    Originally posted by:
    Newsgroup User
    That's how table cells work with no prompting from you, if
    they have no
    width assigned at all.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "rmiman" <[email protected]> wrote in
    message
    news:ev0h1o$a4j$[email protected]..
    > How can I get my CSS sheet to automatically size the
    width of the table
    > cells where text is located?
    >
    >
    http://www.rminc.com/test_examples/test3.html
    I know but let's say I want to have a table with a width of
    600px and 5 columns, 2 of those colums have content and the other 3
    don't. I want those 2 columns with content to automatically size
    themselves but since my table has a width of 600px it won't
    work.

Maybe you are looking for