473,416 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

insert values in new jtable from old one

14
How to insert values from one jtable to another jtable using arraylist(tokenizer).
Expand|Select|Wrap|Line Numbers
  1. private void readPreviousValues() {
  2.         String temps = null;
  3.         StringTokenizer tokenizer;
  4.         for (int i = 0; i < B.size(); i++) {
  5.             tokenizer = new StringTokenizer(B.get(i).toString(), "%%");
  6.             dm.setValueAt(tokenizer.nextToken(), i, 1);
  7.             dm.setValueAt(tokenizer.nextToken(), i, 2);
  8.             dm.setValueAt(tokenizer.nextToken(), i, 3);
  9.             dm.setValueAt(tokenizer.nextToken(), i, 4);
  10.             dm.setValueAt(tokenizer.nextToken(), i, 5);
  11.             temps = tokenizer.nextToken().toString();
  12.             if (temps.equalsIgnoreCase("--")) {
  13.                 dm.setValueAt("", i, 6);
  14.             } else {
  15.                 dm.setValueAt(temps, i, 6);
  16.             }
  17.             temps = tokenizer.nextToken().toString();
  18.             dm.setValueAt(temps, i, 7);
  19.             temps = tokenizer.nextToken().toString();
  20.             dm.setValueAt(temps, i, 8);
  21.         }
  22.     }
  23.  
I'm using this code. But it doesnt works.. I want to print the values from one table to another. can anybody help?
Aug 28 '08 #1
7 2918
JosAH
11,448 Expert 8TB
JTables use TableModels; why don't you fetch the data from the old model and
put it in the new model? There's no need for all that String juggling.

kind regards,

Jos
Aug 28 '08 #2
saiindu
14
Can u give an example for that sir, pls...
Aug 29 '08 #3
JosAH
11,448 Expert 8TB
Can u give an example for that sir, pls...
Why don't you read the API documentation of the JTable and TableModel classes?
Near the top of the JTable documentation is a link to a nice tutorial on the subject
with lots of examples.

kind regards,

Jos
Aug 29 '08 #4
saiindu
14
Actually i'm using the DefaultTableModel in my project. We are using arraylist for each forms to retrieve the data. What i need is to retrieve values given in jtable should be displayed in same table same form with different pages.
Aug 29 '08 #5
JosAH
11,448 Expert 8TB
Actually i'm using the DefaultTableModel in my project. We are using arraylist for each forms to retrieve the data. What i need is to retrieve values given in jtable should be displayed in same table same form with different pages.
Sorry, I don't understand what you mean here; what's wrong with a simple
getValueAt() from the old table and a setValueAt() to the new model? Or use
the addRow() or insertRow() methods on the new model.

kind regards,

Jos
Aug 29 '08 #6
saiindu
14
The form name is B. I'm trying to retrieve the values using
StringTokenizer tokenizer;
for (int i = 0; i < B.size(); i++) {
System.out.println(B.get(i));
}
I want to print this retrieved data in the same jtable overriding the old one. That is using paging.
Aug 29 '08 #7
JosAH
11,448 Expert 8TB
The form name is B. I'm trying to retrieve the values using
StringTokenizer tokenizer;
for (int i = 0; i < B.size(); i++) {
System.out.println(B.get(i));
}
I want to print this retrieved data in the same jtable overriding the old one. That is using paging.
What is the type of that B thing? btw, slowly by slowly your question is moving
towards your other question: pagination of result sets. JTables have not much to
do with that; if your offset in your source table is 'o' and your page size is 'p'
simply fill your JTable with rows [o, min(m, o+p)) where m is the total number of
records in your source table. Adjust o to o+p when you want to page forward in
your table and make it o-p to page back to the top; keep the result offset o in
the range [0, m)

If you're also dealing with SQL here note that there is no portable way to retrieve
records [o, o+p) from a table but most (if not all) SQL engines have proprietary
solutions for this inconvenience. RTFMs.

kind regards,

Jos
Aug 29 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ben Munday | last post by:
Hi all, I have a problem with a Checkbox in a JTable. When i add the Checkbox into the JTable it displays the String representation of the Checkbox, which is not what i want. So, i created a...
1
by: asd | last post by:
I need to make the cells in the 1st column look like the column header. I tried the following code but it didn't change anything: private void rendererTest() { TableColumn column =...
1
by: raysaun | last post by:
I am trying to set a TableCellEditor for a JTable, however, the editor never seems to get called. I can not even get a simplified version (below) to work. When I put a breakpoint on the return...
0
by: sivaprasad06 | last post by:
Hi, I have a editable combo box editor as a cell editor for JTable. I want use only key board to enter data into jtable. so i am using ALT+Down comobination for making cell editiable in the...
0
by: nuria | last post by:
hi, I have an editable JTable, when you are editing it and press F8 shows a dialog and then go again to the JTable window but the focus goes to a JtextField component, go with the tab for the...
1
by: Andrea Sansottera | last post by:
Hi fellows, I was wondering if in the Java API there's a way to easily map a disconnected RowSet to a JTable... I have looked at the doc but i did not found anything. What I want is simply do...
7
oll3i
by: oll3i | last post by:
i want to change the values in two columns one colum is a combobox and the secons column is editable too i want to get the value of that second column and the value of combobox and sent that...
5
by: moizpalitanawala | last post by:
Hello friends, How to add data to JTable from a .txt file. I had seen this code from one of the tutorial from java.com. This code doesnt take any input. But shows what is written in the array....
1
by: saiindu | last post by:
Help me how to retrieve values which is stored in arraylist tokenizer and then make the values to print in jtable records.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.