Home Answers Viewqa Java-Beginners how to insert check box

 
 


raghuveer Gowda
how to insert check box
1 Answer(s)      a year and 8 months ago
Posted in : Java Beginners

how to insert check box into jtable row in swing

View Answers

September 2, 2011 at 1:10 PM


import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;

public class CheckBoxInJTable extends JPanel {

    public CheckBoxInJTable() {
        Object[] columns = new Object[] {"Select", "Name"};
        Object[][] data = new Object[2][2];
        data[0][0] = new Boolean(false);
        data[0][1] = "John";
        data[1][0] = new Boolean(false);
        data[1][1] = "Bill";

        MyTableModel model = new MyTableModel(data, columns);
        JTable table = new JTable(model);

        table.getColumnModel().getColumn(0).setCellEditor(new CheckBoxCellEditor());
        table.getColumnModel().getColumn(0).setCellRenderer(new CWCheckBoxRenderer());
        JScrollPane tableScroller = new JScrollPane(table);
        add(tableScroller);
    }

    private class MyTableModel extends AbstractTableModel {

        private Object[][] data;
        private Object[] columns;

        public MyTableModel(Object[][] data, Object[] columns) {
            this.data = data;
            this.columns = columns;
        }

        public Class getColumnClass(int columnIndex) {
            return data[0][columnIndex].getClass();
        }
        public int getColumnCount() {
            return columns.length;
        }
        public int getRowCount() {
            return data.length;
        }
        public Object getValueAt(int rowIndex, int columnIndex) {
            return data[rowIndex][columnIndex];
        }
              public boolean isCellEditable(int rowIndex, int columnIndex) {
            return (columnIndex == 0 || columnIndex == 2);
        }
    }

    private class CheckBoxCellEditor extends AbstractCellEditor implements TableCellEditor {
        protected JCheckBox checkBox;

        public CheckBoxCellEditor() {
            checkBox = new JCheckBox();
            checkBox.setHorizontalAlignment(SwingConstants.CENTER);
            checkBox.setBackground( Color.white);
        }

        public Component getTableCellEditorComponent(
                JTable table, 
                Object value, 
                boolean isSelected, 
                int row, 
                int column) {

            checkBox.setSelected(((Boolean) value).booleanValue());
            return checkBox;
        }
        public Object getCellEditorValue() {
            return Boolean.valueOf(checkBox.isSelected());
        }
    }

    private class CWCheckBoxRenderer extends JCheckBox implements TableCellRenderer {
    Border border = new EmptyBorder(1,2,1,2);
        public CWCheckBoxRenderer() {
        super();
        setOpaque(true);
        setHorizontalAlignment(SwingConstants.CENTER);
        }

        public Component getTableCellRendererComponent(
        JTable table,
        Object value,
        boolean isSelected,
        boolean hasFocus,
        int row,
        int column) {

        if (value instanceof Boolean) {
        setSelected(((Boolean)value).booleanValue()); 
        setEnabled(table.isCellEditable(row, column));

        if (isSelected) {
        setBackground(table.getSelectionBackground());
        setForeground(table.getSelectionForeground());
        } else {
        setForeground(table.getForeground());
        setBackground(table.getBackground());
        }
        }
        else {
        return null;
        }

        return this; 
        }
         }
        public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        CheckBoxInJTable test = new CheckBoxInJTable();
        f.getContentPane().add(test);
        f.setSize(350, 350);
        f.show();
    }
}









Related Pages:
how to insert check box
how to insert check box   how to insert check box into jtable row in swing
check box left justification
check box left justification  how to make a check box left justification which is at right end? thanks in advance
check box in jsp
check box in jsp  hey guys i am working on a web based project using jsp. In my project 1 am having 9 check boxes in 3 rows in the same form. I want to select 1 check box from each row and also i want to avoid many check box
Check Box Validation in PHP - PHP
Check Box Validation in PHP  How can validations done on check boxes more than 3?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/javascript-array/javascript-array-checkboxes.shtml
Creating Check Box in Java Swing
Creating Check Box in Java Swing       This section illustrates you how to create a Check Box component in Java Swing. In this section, you can learn simply creating the Check Box
click on check box
click on check box  I create a check box in HTML and when i click on my check box relative information in page store in database
How to check a checkbox - Struts
How to check a checkbox  Hello Community, How can i check a checkbox defined with tags. with plain html, the tag checks the box. with the other tags i am getting an error that the property "checked" is not defined. Can someone
HI Jsp check box..!
HI Jsp check box..!  Hi all.. I want to update the multiple values of database table using checkbox..after clicking submit the edited field has to update and rest has to enable to update...please help me..its urgent
Dynamic check box problem
Dynamic check box problem  In my project i have used a dynamic table, in the each row of that table there is one check box [that i have created... check boxes ... pleas help me as soon as possible...   1)application.jsp
check box condition
check box condition  Hai, my application has two check box one for chart and another one for table.when We click chart check box download only chart but table also download.same problem in table slection..xsl coding was used
Check Box Midlet Example
J2ME CheckBox ChoiceGroup MIDlet       This example illustrates how to create check...;, "J2ME", "J2EE", "JSF"). if user select a check box
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  how to insert check box value to the database using jsp my code is <link href="font&colors.css" rel="stylesheet" type="text/css"> <p></p>
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  How to insert check box value to the oracle database using jsp? I want to create hotel's package. where the admin will select the activities to insert in the PACKAGE table. I
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  Hi, how to dynamically increase size of list... insert new course in a table.. It should be seen in my list box
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  How to insert check box value to the oracle database using jsp? I want to create hotel's package. where the admin will select the activities to insert in the PACKAGE table. I
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  hi all, how can i insert elements into java script list box retrieving from Database. whenever I insert any element in the Db
check condition in if-else block
check condition in if-else block  Hi, I want to update database with following query int i= st.executeUpdate("Insert into text_editor(words) values('"+words+"')"); how can I give a check option so only valid words are inserted
check box realtive information in page store in database
check box realtive information in page store in database  check box relative information in page store in database  hiiiiiiiii, Que I create a checkbox in html and when i click on my check box realtive information
check for errors
check for errors  How can I check for errors
JAVASCRIPT insert Question -
JAVASCRIPT insert Question  It is easy to transmit information from HOST program (in my case PHP program) to JAVASCRIPT insert. How may I reverse this, passing YES/NO information from a CONFIRM BOX back to the PHP program
how to insert the selected item of combobox in mysql - XML
how to insert the selected item of combobox in mysql  hi, i have to insert the selected item from combobox into MYSQL database.pls provide... of combobox in mxml.how to insert selecteditem in database. pls suggest me i have
password check
password check  how to check sighup passowrd and login password
how to insert the physical path of an image in database - JDBC
how to insert the physical path of an image in database  hello I m... , the image column is of varchar datatype.. plz can you tell me how to insert image's path.. and also how to retrive that image path and show that picture in a small
how to insert data into database using jsp & retrive
how to insert data into database using jsp & retrive  Hello, I have created 1 html page which contain username, password & submit button. in my.... name is amit and password is ddave. so hw could i check whether the username &
How to check for Empty textboxed and fill it with a value on a button click
How to check for Empty textboxed and fill it with a value on a button... should check if it is empty and should get added to the second target text box... to the target text box and check if second target box is empty. If it is empty
How to create an input box?
How to create an input box?  How to create an input box
How to create a confirmation box?
How to create a confirmation box?  How to create a confirmation box
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB:student; @table:stu_info; Combobox values:(class1,class2,class3); textbox1
instead of text boxe i have to show check box as selected.
instead of text boxe i have to show check box as selected.  i have one text field. in that iam getting boolean value either true or false from... have to show check box as selected. Thanks In advance R.Raveen.
how to insert image into server
how to insert image into server  how to insert an image into sql server and retrieve it using jSP
how to import values from database to the drop down box
how to import values from database to the drop down box   hi iam final year student in my project i will insert all employee details in search employee page i kept a drop down box for employee Ids i want all employee IDs
J2ME Text Box Example
J2ME Text Box Example       This application illustrates how to create the text box using TextBox...) getConstraints() getMaxSize() getString() insert(char[] data, int offset
How to check no records - JSP-Servlet
How to check no records  Hi all, I am developing an onlineshopping project, in that how i have 2 check no records. I saw an answer....... At first when a user registers means, his/her cart is empty na... how
how to check a remote applications validity
how to check a remote applications validity  i am developing a network application to avoid unauthorized access to a port .. for that i need to get the application id . how to get the appln id of an appln. or is there any way
Insert data in mysql database through jsp using prepared statement
; This is detailed jsp code that how to insert data into database by using prepared statement...; // check if the text box is empty if(name!=null && city!=null && phone!=null){ // check if the text box having only blank spaces
How to check whether database exists?
How to check whether database exists?  Hi, I have to create... to creating the database, i want to check whether database exists or not? How can i do this check. can any one help me on this. Please find thesample code
How to insert rows in jTable?
How to insert rows in jTable?  Hi, I need to take input from user using JTable. I want an empty row to appear after clicking a insert button... not figure out how to. I used DefaultTableModel but wasnt able to insert a row
How to insert clob data??
How to insert clob data??  Can any one tell me in details how... to insert more than 4000 characters.I have heard that clob fields can hold 4 gb of data and need pl/sql to avail that feature.Can any one tell me how to create
insert data in the database using checkbox
insert data in the database using checkbox  i am fetching data from... each row but the problem is that i am not fetching data in any textboxes so how should i insert only checked data into database on submission.   We
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you   Please visit the following link: http://www.roseindia.net/jsp/user
Hollow Box
;Hello Friend, Try this: import java.util.*; class Box{ public void check(Scanner...Hollow Box  Write an application program that will draw a hollow box (a box with empty space in between). The program will ask the user to key
How to write a select box and id should be stored in database?
How to write a select box and id should be stored in database?  Hi, How to write a select box and select the name(devi) regarding name id(like 60... is another example that simply insert the selected combobox value and id
check null exception java
check null exception java  check null exception java - How to check the null exception on Java?   The null pointer exception in java occurs... this error. The only way to handle this error is validation. You need to check
how to insert a summary values in grid
how to insert a summary values in grid  how to insert a summary value in grid
jdbc insert
jdbc insert  Hi , i want to insert a declared integer variable into a mysql table through jdbc. how to insert that. help me with query... thanks... a table there. After creating a table in database, it insert a rows in the database
dialog box
dialog box to ask to quit or continue  hello. write an application... of the interview, use a dialog box to ask whether the user wants to - enter another set... question indicate how many users chose the first option,second option and so
dialog box
dialog box to show latest question  hello. write an application... of the interview, use a dialog box to ask whether the user wants to - enter another set... question indicate how many users chose the first option,second option and so
How to check a file exists or not in java.
Description: This example demonstrate how to check a file exits at a given path or not.  The method isFile() of the File class check for its existence. As in the file path we see '\' (backslash) that is used to denote
How to check a file is hidden or not in java
Description: This example demonstrate how to check a file is hidden at a given path or not.  The method isHidden() of the File class check for its hidden property of a file. As in the file path we see '\' (backslash
Customize the Icon in a JCheckBox Component of Java Swing
to customize the icon in a check box component. That means any icon can be shown where the checked or unchecked box of the check box is situated. The specified icon is looked with the given text for the check box. Image for the pictorial

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.