import java.awt.Color;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
public class InsertFileDataToJTable extends AbstractTableModel {
/**
*
*/
private static final long serialVersionUID = 1L;
Vector<String> data;
Vector<String> columns;
int i = 1;
public InsertFileDataToJTable() {
String line;
data = new Vector<String>();
columns = new Vector<String>();
try {
FileReader fr1 = new FileReader("D:\\abc.txt");
BufferedReader br = new BufferedReader(fr1);
StringTokenizer st1 = new StringTokenizer(br.readLine(), " ");
/*while (st1.hasMoreTokens())
columns.addElement(st1.nextToken());*/
int f = 4,l=f+4;
while (i < f) {
br.readLine();
i++;
}
while (f <= l) {
if ((line = br.readLine()) != null) {
StringTokenizer st2 = new StringTokenizer(line, " ");
while (st2.hasMoreTokens())
data.addElement(st2.nextToken());
f++;
}
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
protected String[] columnNames = new String[] {"ID", "NAME", "ADD"};
public int getRowCount() {
return data.size() / getColumnCount();
}
public String getColumnName(int col) { return columnNames[col]; }
public int getColumnCount() {
return columns.size();
}
public Object getValueAt(int rowIndex, int columnIndex) {
String name=(String) data.elementAt((rowIndex * getColumnCount())
+ columnIndex);
return name;
}
public static void main(String s[]) {
InsertFileDataToJTable model = new InsertFileDataToJTable();
JTable table = new JTable();
table.setModel(model);
table.setBackground(Color.orange);
JScrollPane scrollpane = new JScrollPane(table);
JPanel panel = new JPanel();
panel.add(scrollpane);
JFrame frame = new JFrame();
frame.add(panel, "Center");
frame.pack();
frame.setVisible(true);
}
}
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
public class InsertFileDataToJTable extends AbstractTableModel {
/**
*
*/
private static final long serialVersionUID = 1L;
Vector<String> data;
Vector<String> columns;
int i = 1;
public InsertFileDataToJTable() {
String line;
data = new Vector<String>();
columns = new Vector<String>();
try {
FileReader fr1 = new FileReader("D:\\abc.txt");
BufferedReader br = new BufferedReader(fr1);
StringTokenizer st1 = new StringTokenizer(br.readLine(), " ");
/*while (st1.hasMoreTokens())
columns.addElement(st1.nextToken());*/
int f = 4,l=f+4;
while (i < f) {
br.readLine();
i++;
}
while (f <= l) {
if ((line = br.readLine()) != null) {
StringTokenizer st2 = new StringTokenizer(line, " ");
while (st2.hasMoreTokens())
data.addElement(st2.nextToken());
f++;
}
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
protected String[] columnNames = new String[] {"ID", "NAME", "ADD"};
public int getRowCount() {
return data.size() / getColumnCount();
}
public String getColumnName(int col) { return columnNames[col]; }
public int getColumnCount() {
return columns.size();
}
public Object getValueAt(int rowIndex, int columnIndex) {
String name=(String) data.elementAt((rowIndex * getColumnCount())
+ columnIndex);
return name;
}
public static void main(String s[]) {
InsertFileDataToJTable model = new InsertFileDataToJTable();
JTable table = new JTable();
table.setModel(model);
table.setBackground(Color.orange);
JScrollPane scrollpane = new JScrollPane(table);
JPanel panel = new JPanel();
panel.add(scrollpane);
JFrame frame = new JFrame();
frame.add(panel, "Center");
frame.pack();
frame.setVisible(true);
}
}
0 comments:
Post a Comment