Results 1 to 3 of 3
Thread: Having trouble with 2d Array
- 08-02-2010, 04:06 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 25
- Rep Power
- 0
Having trouble with 2d Array
hi,
I would like to add column names and fields entered in text boxes to a JTable, but my code is not compiling. Also, is there a way to set a 2d array to an undetermined size? I'm not sure how many entries there will be. Here is my code:
Java Code:public class CustomerDisplay { JFrame frame = new JFrame(); JPanel panel = new JPanel(); private String [] columnNames = null; private String[][] rowData = null; public CustomerDisplay(String rowData[][], String [] columnNames ) { this.columnNames = columnNames; this.rowData = rowData; JTable table = new JTable(rowData, columnNames); JScrollPane sp = new JScrollPane(table); panel.add(sp); add(panel); } }Java Code:public class Customer extends JPanel { JPanel panel = new JPanel(); private String [] columnNames = {"First Name", "Last Name", "Customer Status", "Dependent Age", "Customer ID"}; private String [][] rowData = new String [10][10]; public Customer() { panel.setLayout(new BorderLayout()); panel.add(new Buttons(), BorderLayout.NORTH); panel.add(new CustomerInformation(), BorderLayout.CENTER); panel.add(new CustomerDisplay(rowData, columnNames), BorderLayout.SOUTH); add(panel); } }
- 08-02-2010, 04:46 AM #2
If your code is not compiling, provide the error message(s) and line number(s) that the compiler gives you.
As far as I know, there is no way to create an array of an undetermined size. However, an array can be resized using the Array.newInstance() method, then System.arraycopy().Last edited by Zack; 08-02-2010 at 04:53 AM.
- 08-02-2010, 04:54 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Post your complete error message here to see. I don't think that anyone wants to compile your code and fix errors for you.
Just looking at your code I've seen that you haven't import any required packages in to the class file.
Similar Threads
-
Having trouble reading external txt file to an array
By Metastar in forum New To JavaReplies: 18Last Post: 07-21-2010, 11:29 PM -
trouble with array method
By kpro862 in forum New To JavaReplies: 6Last Post: 05-12-2010, 12:08 AM -
Array trouble
By hobo in forum New To JavaReplies: 8Last Post: 11-17-2009, 12:04 PM -
[SOLVED] Array trouble....
By AngrYkIdzrUlE in forum New To JavaReplies: 9Last Post: 04-18-2009, 10:18 PM -
Having trouble with array
By ice22 in forum New To JavaReplies: 3Last Post: 11-13-2007, 03:06 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks