• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

displaying a element when added to my JTable

This is going to be pretty hard to explain, but I will do my best.

Right now when I execute my base dialog there is a area with a JTable.  I have a TableModel class where I create the columns and rows.  When the dialog is open and the user adds another object to the table, I want the new object to display in the table.  Right now the only way to get the addition to show is to resize the dialog.  Then it does show.  I would like it to show with out having to resize the dialog.  

I know that I have not given much information above, but tell me what you need to see and I will post it.
0
jkteater
Asked:
jkteater
  • 3
  • 3
  • 2
  • +1
1 Solution
 
CEHJCommented:
You need to ensure that nothing is stopping the gui thread. We need to see code really
0
 
for_yanCommented:
Add repaint() to your dialog - this is usually equivakent to resizing
0
 
Bryan ButlerCommented:
Are you repainting after adding the object? (JTable.repaint())
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
jkteaterAuthor Commented:
What code do you need to see?  Dialog or TableModel?
0
 
for_yanCommented:
Just try repaint() first - that is usual case - should work
0
 
for_yanCommented:
You may also want to say setModel(modl) before repainting
0
 
jkteaterAuthor Commented:
I don't have a add object button or something like that.  I have a class that gets the users selection and that is placed in a array then in my jtable class I am getting the values from the array.  

I will post that class

 
public class SelectedTModel extends AbstractTableModel {
   
   private static final long serialVersionUID = 1L;
   private ArrayList<RevDataset> aList;
   
   static final int ITEMID_COL   = 0;
   static final int REVID_COL    = 1;
   static final int PRL_COL      = 2;
   static final int DATASETNAME_COL  = 3;
   static final int DATASET_COL  = 4;
   
   static final int MAX_COLUMNS  = 5;
      
   //////////////////////////////////////////////////////////////////////////
   //                                                                      //
   //                              Constructor                             //
   //                                                                      //
   //////////////////////////////////////////////////////////////////////////
   public SelectedTModel() {
      super();
      this.aList = EdiSelection.rds;	
      if(aList == null) aList = new ArrayList<RevDataset>(); 
                
   } // end constructor
   
   //////////////////////////////////////////////////////////////////////////
   //                                                                      //
   //                             getColumnCount()                         //
   //                                                                      //
   //////////////////////////////////////////////////////////////////////////
   public int getColumnCount() {
	   
      return MAX_COLUMNS;
   } // end getColumnCount()
   
   //////////////////////////////////////////////////////////////////////////
   //                                                                      //
   //                             getRowCount()                            //
   //                                                                      //
   //////////////////////////////////////////////////////////////////////////   
   public int getRowCount() {
      return aList.size();
	  
   } // end getRowCount()
   
   //////////////////////////////////////////////////////////////////////////
   //                                                                      //
   //                             getValueAt()                             //
   //                                                                      //
   //////////////////////////////////////////////////////////////////////////  
   public Object getValueAt(int row, int column){
      Object o = null;
           
	  try {	   
	     switch (column) {
	        case ITEMID_COL: { o = aList.get(row).rev.getItem().getStringProperty("item_id"); break; }
	        case REVID_COL: { o = aList.get(row).rev.getStringProperty("item_revision_id"); break; }
	        case PRL_COL: { o = aList.get(row).rev.getRelatedComponent("IMAN_master_form_rev").getStringProperty("PRL"); break; }
	        case DATASETNAME_COL: { o = aList.get(row).componentdataset.getStringProperty("object_string"); break; }
	        case DATASET_COL: { o = aList.get(row).componentdataset.getStringProperty("object_type"); break; }
	     }
	  }
	  catch (Exception e) {
	     e.printStackTrace();
	 
      } 
      return o;
   }
   
   //////////////////////////////////////////////////////////////////////////
   //                                                                      //
   //                             getColumnName()                          //
   //                                                                      //
   //////////////////////////////////////////////////////////////////////////
   public String getColumnName(int column) {
      String s = null;
      
      switch (column) {
      case ITEMID_COL:   { s = "ItemId"; break; }
      case REVID_COL:    { s = "RevId"; break; }
      case PRL_COL:      { s = "PRL"; break; }
      case DATASETNAME_COL:  { s = "Dataset Name"; break; }
      case DATASET_COL:  { s = "Dataset Type"; break; }
      }
   return s;
   } // end getColumnName()
 
}//end SelectedTModel

Open in new window

0
 
CEHJCommented:
You need to implement the correct updating methods in your TableModel

http://download.oracle.com/javase/6/docs/api/javax/swing/table/AbstractTableModel.html#fireTableDataChanged()

(and others if necessary)
0
 
CEHJCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now