A quick Question:
I'm trying to import some information from a CSV into a jtable that is located on a swing panel in my program.
I've imported the information into the actionListener using inputstream and parsed through it with bufferedreader. I just used a simple while loop afterwards to add to the Jtable. however, when I run the app, no information shows up in my jtable.
When I try to debug the program, I have no issues toggling between the two jpanels (and the other information that is on them) its just my jtable that shows up empty.
Here's my code:
public class wert extends JFrame {
private JPanel contentPane;
private JPanel panel;
private JTable table;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
wert frame = new wert();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public wert() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 925, 486);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
JButton btnNewButton = new JButton("New button");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
Path filePath = Paths.get("\\test folder\\newNeetest.csv\\");
InputStream input = null;
input = Files.newInputStream(filePath);
BufferedReader reader = new BufferedReader (new InputStreamReader(input));
DefaultTableModel model = (DefaultTableModel)table.getModel();
Object [] lines = reader.lines().toArray();
for (int q =0; q > lines.length; q++) {
String dsa = lines[q].toString();
String [] dataRow = dsa.split(",");
model.addRow(dataRow);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
);
contentPane.add(btnNewButton, BorderLayout.NORTH);
panel = new JPanel();
contentPane.add(panel, BorderLayout.CENTER);
table = new JTable();
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addGap(475)
.addComponent(table, GroupLayout.PREFERRED_SIZE, 230, GroupLayout.PREFERRED_SIZE)
.addContainerGap(188, Short.MAX_VALUE))
);
gl_panel.setVerticalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
.addContainerGap()
.addComponent(table, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
.addGap(375))
);
panel.setLayout(gl_panel);
}
}