Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Help with the CheckBox button in JTable

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with the CheckBox button in JTable

    .............................
    Last edited by Yamato; December 8th, 2010 at 05:40 AM.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Help with the CheckBox button in JTable

    While the user checked the checkbox, it will not appear that row on the next Run.
    I have no idea what you mean by: "appear that row on the next run". Can you explain what is happening because I am unclear.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with the CheckBox button in JTable

    ............................
    Last edited by Yamato; December 8th, 2010 at 05:41 AM.

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Help with the CheckBox button in JTable

    class StockEnquiryStaff implements Comparable {
    public String name;
    public String telephone;
    public String callback;
    public String enquiry;
    public Boolean check;
     
    public StockEnquiryStaff(String n, String t, String c, String e, Boolean ck){
    this.name = n;
    this.telephone = t;
    this.callback = c;
    this.enquiry = e;
    this.check = ck;
    }
     
    public String getName() {
    return name;
    }
    public String getTelephone() {
    return telephone;
    }
    public String getCallback() {
    return callback;
    }
    public String getEnquiry() {
    return enquiry;
    }
    public Boolean getCheck() {
    return check;
    }
    public int compareTo(Object o) {
    StockEnquiryStaff temp = (StockEnquiryStaff) o;
    return (callback.compareTo(temp.callback));
    }
    }
     
    ---------------------------------------------------------------------------------------
     
     
    //This is how i set the column 5 to become a checkbox
    class ATableClass extends JTable {
    public Class getColumnClass(int column) {
    try {
    if (column == 4) {
    return Class.forName("java.lang.Boolean");
    }
    return Class.forName("java.lang.Object");
    }
    catch (ClassNotFoundException ex) {
    ex.printStackTrace();
    return null;
    }
    }
    }
     
    ----------------------------------------------------------------------------
     
     
    //This is the Stock Enquiry class which contain Jtable, button, text field and Jlabel.
    public class StockEnquiryStaffView extends JFrame {
     
    // A container for the Product instances
    ArrayList StockEnquiriesStaff = new ArrayList();
     
    // StockEnquiryStaffView bits and bobs
    JPanel panInput = new JPanel(new GridLayout(4,20)),
    panAdd = new JPanel(),
    panDelSort = new JPanel();
     
    JTextField txtName = new JTextField(10),
    txtTelephone = new JTextField(10),
    txtCallback = new JTextField(5),
    txtEnquiry = new JTextField(20);
     
    JButton btnAdd = new JButton("Add"),
    btnDelete = new JButton("Delete"),
    btnSort = new JButton("Sort Callback Time by Ascending"),
    btnSort1 = new JButton("Sort Callback Time by Descending"),
    btnSave = new JButton("Save");
     
     
    ATableClass tableOne = new ATableClass();
    DefaultTableModel tabMod = new DefaultTableModel();
     
     
    //This is the read file method which read from text file and using the loadProductsIntoTable
    //to load all the data into the JTable.
    public void readfile() throws IOException {
    BufferedReader br = new BufferedReader(
    new FileReader("salesEnquiryLog.txt"));
    String s;
    String getName = "";
    String getTelephone = "";
    String getCallback = "";
    String getEnquiry = "";
    Boolean getCheck = null;
    int i = 0;
    while((s = br.readLine()) != null) {
    if (s.equals("<sales_enquiry>")) {
    getName = br.readLine();
    getTelephone = br.readLine();
    getCallback = br.readLine();
    getEnquiry = br.readLine();
    StockEnquiryStaff [] StockEnquiries = {new StockEnquiryStaff(getName, getTelephone,getCallback,getEnquiry, getCheck)};
    StockEnquiriesStaff.add(StockEnquiries[i]);
    loadProductsIntoTable();
    }
     
    }
    }
     
     
     
    // This is the method of load all the data in the product array into the JTable (row by row).
    public void loadProductsIntoTable() {
    tabMod.setRowCount(0);
    String [] row = new String [4];
    for (Iterator i = StockEnquiriesStaff.iterator(); i.hasNext() {
    StockEnquiryStaff temp = (StockEnquiryStaff) i.next();
    row[0] = temp.getName();
    row[1] = temp.getTelephone();
    row[2] = temp.getCallback();
    row[3] = temp.getEnquiry();
    tabMod.addRow(row);
    }
    }
     
     
     
    //Stock Enquiry
    public StockEnquiryStaffView() throws IOException {
    super("Stock Enquiry Staff View");
    tableOne.setModel(tabMod);
    tabMod.addColumn("Manager Name");
    tabMod.addColumn("Telephone");
    tabMod.addColumn("Callback Time");
    tabMod.addColumn("Enquiry");
    tabMod.addColumn("Check");
    // All the btn, txt, jlabel here
     
     
     
    ------------------------------------------------------------------------------------------

    Looks like it's reading a name, a number, and a time.

  5. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with the CheckBox button in JTable

    ....................
    Last edited by Yamato; December 8th, 2010 at 05:42 AM.

Similar Threads

  1. Checking the Status of a checkbox
    By michaelz in forum Object Oriented Programming
    Replies: 16
    Last Post: August 9th, 2010, 06:44 AM
  2. how to delete record from checking checkbox value.
    By -_- in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: March 12th, 2010, 07:09 AM
  3. Checkbox - Change Font Color
    By wakebrdr77 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 10th, 2010, 10:57 AM
  4. how to delete record based on checkbox selected checkbox
    By -_- in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: December 15th, 2009, 09:26 PM
  5. setEnabled causing checkbox to deselect
    By dewboy3d in forum AWT / Java Swing
    Replies: 3
    Last Post: May 21st, 2009, 11:36 AM