java - JTable with editable checkbox -


The code below is one of my project class. It will produce a frame with jtable when I click Find button Some data will be loaded into the table dynamically. The last column of the table should be the checkbox with the event. I have tried this code for the checkbox (it is not being taken from any other project ... not working)

  DefaultTableModel dtm = New DefaultTableModel (Data, colName) {Public class GetColumnClass (int c) {return (c == 5? Boolean class: string class); }};   

Actual class

  public class BookReturnPanel {JPanel retunBookPanel; JTextField txtRegNo; Jebton BTNFind, BTN Save; JTable retunTable = Faucet; Public JScrollPane jScrollPane = null; Private IT; Static object [] [] data; String regNo = null; Member member = null; Default table modell model = new defaultTableModel (); / ** * Create Panel * / Public BookReturnPanel () {} Public JPanel getRetunBookPanel () {if (retunBookPanel == zero) {retunBookPanel = new JPanel (); RetunBookPanel.setLayout (zero); Model.addColumn ("subscribers"); Model.addColumn ("book"); Model.addColumn ("Issue Issue"); Model.addColumn ("Return Date"); Model.addColumn ("The Return"); RetunTable = new JTable (model); RetunTable.setLocation (new point (0, 60)); RetunTable.setSize (new dimension (517, 386)); JLABEL LBLREGNO = new JLABEL ("Member Reg No:"); LblRegNo.setBounds (24, 40, 108, 14); RetunBookPanel.add (lblRegNo); RetunBookPanel.add (getJScrollPane (), border layout.Setter); TxtRegNo = new JTextField (); TxtRegNo.setBounds (12 9, 37, 200, 20); RetunBookPanel.add (txtRegNo); TxtRegNo.setColumns (10); BtnFind = new pocket ("search"); Btnfif.bets (35 9, 36, 91, 23); BtnFind.addActionListener (@ Override Public Voice ActionPerfed (Action Event E) {if (model.getRowCount ()> 0) {for (int i = model.getRowCount () - 1; i & gt; 1; I--) {model.removeRow (i);}} regNo = txtRegNo.getText (); Member = ServiceFactory.getMemberServiceImpl (). FindByregNo (regNo); List & lt; Issue> issues = ServiceFactory.getIssueServiceImpl () .FindAllIssueByMemberId (for members .getSerialNo ()); (Issue Issues: Issues) {Vector  gt; line = new vector & lt; object & gt; (); line.add element (issue. GetMemberId (). GetName ()); row.addElement (issue.getBookId () .getName ()); row.addElement (issue.getIssueDate ()); row.addElement (issue. GetReturnDate ()); row.addElement (issue.getStatus ()); model.addRow (line);}}}); RetunBookPanel.add (btnFind); BTNS service = new pocket ("save"); BTNS service.Setbound (425, 448, 91, 23); RetunBookPanel.add (btnSave); } Return retunBookPanel; } Private JScrollPane getJScrollPane () {if (jScrollPane == empty) {jScrollPane = new JScrollPane (); JScrollPane.setBounds (new rectangle (0, 60, 517, 386)); JScrollPane.setViewportView (retunTable); } Returned JScrollPane; }}   

Prepare the code above JTable but I need to show the JCheckbox on the last column. A checkbox is clicked when the event is required to add !!

1) JTable column starts with serial number 0, if you select < If you want to set the code> JCheckBox to the last column, you do not need to use index 4, 5 as your code. For example:

2) For example: With JCheckBox you can add jobs to your JCheckBox column using DefaultCellEditor For example,: JCheckBox chb = new jacquet box (); Chb.addItemListener (New Item Listener) {@ Override Public Wide ItemSet Event (Event Item E) {System.out.println ("Action");}}); DefaultCellEditor Editor = new DefaultCellEditor (chb) {@Override public component getTableCellEditorComponent (JTable table, object value, boolean, selected, int row, int column) {Component table cell editor Companent = super .getTableCellEditorComponent (table, value, selected, row , Column); (JCheckBox) tableCellEditorComponent) .setHorizontalAlignment (JCheckBox.CENTER); Return tablecelendor time; }}; RetunTable.getColumnModel () getColumn (4) .setCellEditor (editor) .;

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -