Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

displaying a element when added to my JTable

Posted on 2011-10-11
9
Medium Priority
?
170 Views
Last Modified: 2012-05-12
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
Comment
Question by:jkteater
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 36949656
You need to ensure that nothing is stopping the gui thread. We need to see code really
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36949672
Add repaint() to your dialog - this is usually equivakent to resizing
0
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 36949682
Are you repainting after adding the object? (JTable.repaint())
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:jkteater
ID: 36949718
What code do you need to see?  Dialog or TableModel?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36949736
Just try repaint() first - that is usual case - should work
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36949749
You may also want to say setModel(modl) before repainting
0
 

Author Comment

by:jkteater
ID: 36949891
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 1000 total points
ID: 36949991
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 36992900
:)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question