java - Disable particular row in JTable using data from database -


After the

I was thinking if it is possible the departure gray or having to present some lines in my JTable Is invisible using data from my data base?

These are columns in my JTable:

  Public DutyModel (ArrayList & gt; Duty & gt; listOfObjects) {ROWCOUNT = listOfObjects.size (); Colcount = columnNames.length; Data = new object [pantheatotta] [callcount]; For an example (int i = 0; i & lt; ROWCOUNT; i ++) {/ * MyObject * / Duty d1 = (Duty) (an example of listOfObjects.get (i)), copy an ArrayList element; Data [i] [0] = d1.getDutyId (); Data [i] [1] = d1.getDutyName (); Data [i] [2] = d1.getDutyDesc (); Data [i] [3] = d1.getDutySectorName (); Data [i] [4] = d1.getDutyStatus (); }}  

When my table is displayed, I want to do the rows with d1.getDutyStatus () where dutystatus = "inactive" to be carried out in depth. My table can be currently updated with "active" (by pressing the update button), or "inactive" (by pressing the delete button). I do not want the user to be able to edit any duties that are in the position of "inactive" duty. Any assistance or help is greatly appreciated. Thanks!

What is the code given below when the user selects a line in JTable and presses the "Update" and "Delete" button Apart from , I run my code Trying to use a 3-level structure, my controller class is RetrieveDutyControl and my unit is Duty.

  public zero-actionPerformed (ActionEvent e) {int rowSelected = tblDutyList.getSelectedRow (); If (line selected> gt = =) {string id = d = tblDutyList.getValueAt (row selected, 0) .toString (); String name = tblDutyList.getValueAt (row selected, 1) .toString (); String desc = tblDutyList.getValueAt (row selected, 2) .toString (); String field = tblDutyList.getValueAt (row selected, 3) .toString (); String position = tblDutyList.getValueAt (row selected, 4) .toString (); Duty duty = new duty (integer. PRIITIT), name, post, area, position); Recovery Duty Control rdc = New Recovery Duty Control (); ArrayList & LT; Duty & gt; Duty list = rdc.processRetrieveDuties (duty); Japanese content page = new deleted duty form (MyFreem, duty); MyFrame.getContentPane () removeAll () .; MyFrame.setContentPane (contentPane); MyFrame.setVisible (true); } Else {JOptionPane.showMessageDialog (blank, "no record selected", "alert", joptionpan. ARROOM_memeg); }  

Try prepareRenderer (with overridden) method Gray line out

sample code: (use the value of the first column to validate)

  object [] columnNames = { " A "," B "," C "," D "}; Object [] [] data = {{ "abc", the new double (850.503), 53, true}, { "LMN", a new double (36k23,254), 6, false}, { "PQR", new Double (8.3), 7, false}, {"xyz", new double (246.0 9 43), 23, true}}; JTable table = new JTable (data, COLUMNNAMES) {@Override public java.awt.Component prepareRenderer (TableCellRenderer renderer, int row, int col) {java.awt.Component comp = super.prepareRenderer (renderer, row, column); Object value = getModel () GetValueAt (line, 0); If (value.equals ("lmn") {comp.setBackground (Color.lightGray); } And {comp.setBackground (Color.white); } Return comp; }};  

enter image description here


< P> Check the value for the button and do nothing.

How to get the value of the selected row?

  if (table.getSelectedRow) = - 1) {int rowIndex = table.getSelectedRow (); Object value = table.getModel (). GetValueAt (rowIndex, 0); If (value.equals ( "lmn")) {// nothing to do} Second {// desired performance}}  

Comments

Popular posts from this blog

Python Equivalent for matlab cart2pol and pol2cart -

Docker - Tomcat and PostgreSQL containers in same host - No Route to host -

java - Joda Time Interval Not returning what I expect -