Hi all,
I am just having problems starting a bit of code to extract values from JTable so that I can eventually say them as a CSV file for viewing on Excel. Currently I have a JTable created using the following code:
package com.alpha;
import javax.swing.*;
import java.awt.*;
public class JTableComponent{
public static void main(String[] args)
{
new JTableComponent();
}
public JTableComponent(){
JFrame frame = new JFrame("Whiteboard Test");
JPanel panel = new JPanel();
String data[][] = {{"Company A","1000","1"},{"Company B","2000","2"},
{"Company C","3000","3"},{"Company D","4000","4"}};
String col[] = {"Company Name","Shares","Price"};
JTable table = new JTable(data,col);
panel.add(table,BorderLayout.CENTER);
frame.add(panel);
frame.setSize(300,200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
I have started a new class that will be called whenever the "Export to CSV" button is pressed. I will implement the button listeners etc at a later stage, right now I would like a few pointers on how to create the for look that will go through the columns and rows looking for the values contained in them. Just a note, the JTable will be scalable, the current JTable is just for test purposes. I know there are APIs available such as the Apache one however I would prefer not to use them.
package com.alpha;
public class Exporter extends JTableComponent
{
public changeToCSV(){
}
public changeToCSV()
{
for(int j = 0; j < table.getColumnCount(); j++) {
}
}
I am having trouble deciding what the constructor should expect to receive. Many thanks for your help in advance!