Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Abstract table model help adding the insert row method too it

  1. #1
    kevinn205 is offline Member
    Join Date
    Nov 2011
    Posts
    65
    Rep Power
    0

    Default Abstract table model help adding the insert row method too it

    Hey, Does anyone know how to add the insert row method to the abstract table model? I assume it looks something like

    public void insertRow(int i, Object[] objects)
    {}

    Any help would be appreciated thank you!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Abstract table model help adding the insert row method too it

    The adding of the row will all depend on what you're using as the nucleus for your AbstractTableModel's data. Knowing this, you should understand how to add a new row. The only tricks I know of are that you have to fire the most specific notification method of the model after you've added the data, in this situation that would be fireTableRowsInserted(...).

  3. #3
    kevinn205 is offline Member
    Join Date
    Nov 2011
    Posts
    65
    Rep Power
    0

    Default Re: Abstract table model help adding the insert row method too it

    Thank you, Any possible way these two code snippets could help to further help me?

    // this is what i use to intiate my table
    Object data[][] = {{"A","b","C","d","e","F",new Boolean(false)}};
    String col[] = {"Company","Date/Time","Reason","Note","Name","Number","Status"};
    // this adds information to the tabl
    "SELECT * from info;
    while(rs.next())
    { String InfoID = rs.getString("InfoID");


    model.insertRow(0,new Object[]{Company,DateNTime,Reason,Note,Name,Number});

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Abstract table model help adding the insert row method too it

    If you're using an AbstractTableModel (and not DefaultTableModel), don't use arrays as the nucleus of the model. Use an ArrayList of some class that represents the row of data. Next you really should read the Swing tutorial on how to use AbstractTableModels as it would help you understand things much better.

  5. #5
    kevinn205 is offline Member
    Join Date
    Nov 2011
    Posts
    65
    Rep Power
    0

    Default Re: Abstract table model help adding the insert row method too it

    So bassicly I should store my data into a seperate class that is an arraylist? then somehow synch it with the arraylist or add the arraylist? How would I go about either of those? Is this class at all of track? if so how would I call it


    Or would there be another acceptable soulution that would give me the ability to individualy add data to the table from my query?

    Java Code:
    public class Info
    {
    	public static String InfoID;
    	public static  String CompanyID;
    	public static String DateNTime;
    	public static String Name;
    	public static String Number;
    	public static String Reason;
    	public static String Note;
    	public static String Company;
    	public static String ContactID;
    	
    
    
    	public Info()
    	{
    		this("","","", "","","");
    	}
    
    	public Info(String InfoID, String CompanyID, String ContactID, String DateNTime,String Reason,String Note)
    	{
    		this.InfoID = InfoID;
    		this.CompanyID = CompanyID;
    		this.ContactID = ContactID;
    		this.DateNTime = DateNTime;
    		this.Reason = Reason;
    		this.Note = Note;
    		
    	}
    	
    	public void setCompany(String Company)
    	{
    		this.Company = Company;	
    	}
    	public String getCompany(){
    		return Company;
    }
    	
    
    	public void setInfoID(String InfoID)
    	{
    		this.InfoID = InfoID;
    	}
    
    	public String getInfoID(){
    		return InfoID;
    }
    	
    	public void setContactID(String ContactID)
    	{
    		this.ContactID = ContactID;
    }
    	
    	public String getContactID(){
    		return ContactID;
    		}
    	
    	public void setCompanyID(String CompanyID)
    	{
    		this.CompanyID = CompanyID;
    }
    	
    	public String getCompanyID(){
    		return CompanyID;
    		}
    	
    	public void setDateNTime(String DateNTime)
    	{
    		this.DateNTime = DateNTime;
    	}
    
    	public String getDateNTime()
    	{
    		return DateNTime;
    	}
    	public void Reason(String Reason)
    	{
    		this.Reason = Reason;
    	}
    
    	public String getReason()
    	{
    		return Reason;
    	}
    	public void Note(String Note)
    	{
    		this.Note = Note;
    	}
    
    	public String getNote()
    	{
    		return Note;
    	}
    
    	public void Name(String Name)
    	{
    		this.Name = Name;
    	}
    
    	public String getName()
    	{
    		return Name;
    	}
    	public void Number(String Number)
    	{
    		this.Number = Number;
    	}
    
    	public String getNumber()
    	{
    		return Number;
    	}
        public boolean equals(Object object)
        {
            if (object instanceof Info)
            {
                Info Info2 = (Info) object;
                if
                (
                    InfoID.equals(Info2.getInfoID()) &&
                    CompanyID.equals(Info2.getCompanyID()) &&
                    ContactID.equals(Info2.getContactID()) &&
                    DateNTime.equals(Info2.getDateNTime()) &&
                    Reason.equals(Info2.getReason()) &&
                    Note.equals(Info2.getNote()) 
                  
                  
                )
                    return true;
            }
            return false;
        }
    
    	public String toString()
    	{
    		return "InfoID:" + InfoID + "\n" +
    			   "CompanyID: " + CompanyID + "\n" +
    			   "ContactID: " + ContactID + "\n" +
    			   "DateNTime:" + DateNTime + "\n"+
    				"Reason: " + Reason + "\n"+
    				"Note: " + Note + "\n";
    				
    	}
    }
    //This is unused formula that is used for formatting
    //public String getFormattedPrice()
    //{
    	//NumberFormat currency = NumberFormat.getCurrencyInstance();
    	//return currency.format(price);
    //}

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Abstract table model help adding the insert row method too it

    Why are all those fields static? You do understand that this renders this class useless, right?

  7. #7
    kevinn205 is offline Member
    Join Date
    Nov 2011
    Posts
    65
    Rep Power
    0

    Default Re: Abstract table model help adding the insert row method too it

    I didn't, I tend to rely on my ide for things like static and void, whenever it doesnt work I try the other :D

    I'm pretty new to programming, basicly i've been doing alot with mysql and jtables using connection streams and connetion pooling to make them interact to other computers over the network, aww and fun old autocomplete/ multi fill Jcomboboxes

    I made a program that is a basic erp/crm software that has the ability to track data then send it to a jtable using mysql, however my problem is that I wanted to add a checkbox to the last column of it so it seems like i need to override or use a abstract table model

    my program works as a server that i can access but now i need to rewrite it so that it will work with the checkbox :( I'm sure youve seen that before in your programming experiences

    mostly im looking for a way to link my data to a object or arraylist then directly link that to my jtable or for a method that allows me to add data individualy to my abstract table method

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Abstract table model help adding the insert row method too it

    Quote Originally Posted by kevinn205 View Post
    I didn't, I tend to rely on my ide for things like static and void, whenever it doesnt work I try the other :D
    That's not good. You really need to understand what static means and why you shouldn't be using it here, and I strongly urge that you learn Java basics before working with Swing and trying something as complex as creating your own AbstractTableModel. My experience here trying to help folks in similar situations has been one of nothing but pain and frustration for all until the basics have been learned reasonably well.
    Last edited by Fubarable; 12-03-2011 at 05:34 AM.
    DarrylBurke likes this.

Similar Threads

  1. Replies: 4
    Last Post: 02-19-2011, 05:32 AM
  2. Replies: 1
    Last Post: 12-17-2010, 10:24 AM
  3. Replies: 3
    Last Post: 08-13-2010, 05:57 AM
  4. Copy Default table model to another default table model?
    By greatmajestics in forum AWT / Swing
    Replies: 2
    Last Post: 04-28-2010, 05:08 PM
  5. Replies: 1
    Last Post: 01-08-2010, 07:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •