I have a mainPanel ,there is a button in mainPanel, on the click of that button, textPanel becomes active ,inside textpanel ,only a comobox appears at first,when you select any item from combobox a table displayed with the data corresponding to that
mainPanel->textPanel->Panelc2->F1Table
mainPanel->textPanel->Panelc1->box2
When I do this first time it works properly ,but when I again select some item then it does not refresh the table and show the same data.The problem is not related to data,I think there is something I am missing in java swings.I am new to Swings.Please give some suggestion,If anybody can look into it
Code:
public void box2actionPerformed(ActionEvent event)
{
try
{
String str=(String)box2.getSelectedItem();
Pattern pat=Pattern.compile("//[(.)*//]");
Matcher patMatcher=pat.matcher(str);
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
FileSystem fs = FileSystem.get(conf);
String location="hdfs://localhost:54310/user/a.txt";
modelF1 = new DefaultTableModel();
F1Table=new JTable(modelF1);
modelF1.addColumn("Data");
System.out.println(modelF1.getRowCount());
if (modelF1.getRowCount() > 0) {
for (int i = modelF1.getRowCount() - 1; i > -1; i--) {
modelF1.removeRow(i);
System.out.println(i);
}
}
//modelF1.fireTableDataChanged();
if (modelF1.getRowCount() ==-1) {
System.out.println("no data");
F1Table.removeAll();
}
rowCount=0;
panelC2=new JPanel();
panelC2.repaint();
panelC2.revalidate();
textPanel3.revalidate();
textPanel3.repaint();
mainPanel.revalidate();
mainPanel.repaint();
Path perr=new Path(location);
BufferedReader breader1=new BufferedReader(new InputStreamReader(fs.open(perr)));
String line="";
modelF1 = new DefaultTableModel();
modelF1.fireTableDataChanged();
F1Table=new JTable(modelF1);
modelF1.addColumn("Data");
if(patMatcher.find())
{
String patVal=str.substring(patMatcher.start(), patMatcher.end());
System.out.println(patVal);
while((line=breader1.readLine()) != null)
{
Matcher patMatcherl=pat.matcher(line);
if(patMatcherl.find())
{
String patVall=line.substring(patMatcherl.start(), patMatcherl.end());
System.out.println(patVall);
if(patVal.equals(patVall))
{
modelF1.addRow(new Object[]{line});
}
}
}
}
breader1.close();
modelF1.fireTableDataChanged();
F1scrollPanel = new JScrollPane(F1Table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
F1Table.setPreferredSize(new Dimension(1000, 450));
F1Table.setSize(1000,450);
F1scrollPanel.setPreferredSize(new Dimension(1000, 450));
F1scrollPanel.setSize(1000,450);
panelC2.setPreferredSize(new Dimension(1000, 520));
panelC2.setSize(1000,520);
progressBar.setValue(100);
F1Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
panelC2.add(F1,BorderLayout.NORTH);
panelC2.add(F1scrollPanel,BorderLayout.SOUTH);
textPanel3.add(panelC2,BorderLayout.CENTER);
textPanel3.revalidate();
textPanel3.repaint();
mainPanel.revalidate();
mainPanel.repaint();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void buttonclickactionPerformed(ActionEvent event)
{
try
{
String filepath=pathonconsole.getText();
filepath=filepath.trim();
String filename=filepath.substring(filepath.lastIndexOf('/') + 1);
int i=0;
textPanel3=new JPanel();
textPanel3.setPreferredSize(new Dimension(1100,600));
textPanel3.setSize(1100,600);
box2=new JComboBox();
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
FileSystem fs = FileSystem.get(conf);
String location="hdfs://localhost:54310/user/b.txt";
Path pcor=new Path(location);
BufferedReader breader1=new BufferedReader(new InputStreamReader(fs.open(pcor)));
String line="";
while((line=breader1.readLine())!=null)
{
box2.addItem(line);
}
breader1.close();
box2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
box2actionPerformed(evt);
}
});
panelC1=new JPanel();
box2.setPreferredSize(new Dimension(150, 30));
box2.setSize(150,30);
panelC1.setPreferredSize(new Dimension(1100, 40));
panelC1.setSize(1100, 40);
panelC1.add(box2,BorderLayout.NORTH);
FlowLayout obj=new FlowLayout(FlowLayout.CENTER);
textPanel3.setLayout(obj);
textPanel3.add(panelC1);
mainPanel.add(textPanel3,BorderLayout.CENTER);
System.out.println("added in main panel");
textPanel3.setVisible(true);
System.out.println("done");
}
catch (Exception e) {
e.printStackTrace();
}
}