Hello All! I'm a bit new to Java, and certainly to the community. I'd appreciate any and all pointers to the right direction!
I have a JTable that I have populated with a 2 dimensional array. During the period of the data sitting there, it will be modified. When finished, I would of course like to export it back to a 2 dimensional array.
I really have no clue on the best way of doing this. I assume JTables do not have a 2-dim array for it's backend, and probably uses a vector or something.
My first attempt at a solution was to create a new 2 dim array with dimensions JTable.getColumnlCount() and JTable.getRowCount(). When I do this though, I'm continually getting out of bounds exceptions. I presume this comes from the rowCount and ColCount methods not actually being the size of everything I'm reading it.
Does anyone know what's causing this, or better yet a superior way to export my data to an array?
THANKS!
Rob
5 5197
Hi,
Have you tried debugging the code? Step through if you are using an IDE with a debugger or use good old System.out and see the values at the critical places. You will probably get it over with this way.
Also a JTable does not care how you store the data. It can be an array, vector or anything as long as you can supply the data as required. You actually manage the *back end*.
And of course, seeing the code where you are stuck will help us answer you better.
rgds,
Alex.
A JTable leaves the storage of the actual data to a TableModel which is an interface. Feel free to implement that interface by using a two dimensional array. There is no need to im/export anything then.
kind regards,
Jos
-
public JScrollPane addCSVTable (File newFile) throws IOException
-
{
-
-
CSVDoc csv = new CSVDoc(newFile);
-
String[] columnNames = csv.getHeaders();
-
-
String[][] data = csv.getArray();
-
-
-
-
final JTable table = new JTable(data, columnNames);
-
table.setAutoResizeMode(table.AUTO_RESIZE_OFF);
-
JScrollPane scrollPane = new JScrollPane(table);
-
-
-
return scrollPane;
-
-
}
-
-
this is how I create each table. Then the scrollPane is placed within a JSplitPane, which is then put in a tab.
I see there's a few constructors for the JTable that takes a TableModel as a parameter. I guess my only question with implementing this is, how do I go about adding my header data?
Did you read the appropriate API documentation? It's all in there; in the sticky article "Read This First" you'll find a link which lets you download the entire documentation on your hard disk. Download and read it; it is worth it.
kind regards,
Jos
I have read through the documentation for it - my confusion was coming from what appears to be only getter methods (at least documented) for the tablemodel.
Nevertheless, as I'm sure you suspected, because of counters not matching up properly. I had my rowCount and colCount crossed at one point, and thus the array was populating the width as height and vice versa.
Thanks for the link for the downloadable documentation, very handy.
Thanks again all!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
by: The Garbage Collector |
last post by:
Hey guys,
Heres something I used to do very commonly in java, and I'm having a
hard time coming up with a good paradigm for how to manage this in c#.
In Java, to show data on a grid, you need to...
|
by: onsir |
last post by:
I have code like this, but still wrong.
how to show data from database in JTable.
package my.JavaNetBean;
import java.sql.*;
import java.io.*;
import java.sql.Connection;
import...
|
by: blazedaces |
last post by:
Hi guys, what I'm I have is a jtable with boolean variables in the first column and text in the next two (checkboxes). I want my tableChanged method to make it so when I check one of the checkboxes...
|
by: san1014 |
last post by:
Hi to all'
I am using Java swings.
I written a code to display a table. In the table i used Boolean.class type column.
when i click the checkbox it value to be change from false to true....
|
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....
|
by: emekadavid |
last post by:
can anyone help me flesh out the problem?
I wanted to insert a combo box into one of the columns of
a JTable. although the combo box is drawn, the list
of the data model fails to render.
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
| |