Reference to the given code..i can access the print statement inside the if statement in for-loop(inside try-catch block) but the checkboxes are not adding. I am using the revalidating and repaint function but still its not working. The for loop inside the try-catch block is running except for the adding jscrollpane. Where am i wrong?
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anurag;
import com.anurag.HttpURLConnectionExample;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
/**
*
* @author Anurag
*/
public class MainGui {
static JFrame frame = new JFrame("Rest Testing");
public static void main(String args[]) {
frame.setLayout(new FlowLayout());
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextField path = new JTextField("getresponse.xls");
frame.add(path);
JButton upload = new JButton("Upload");
frame.add(upload);
upload.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
JScrollPane jscrlpLabel = new JScrollPane(new JLabel(
"<HTML>A<br>B<br>C<br>D<br>E<br>F<br>G<br>H<br></HTML>"));
jscrlpLabel.setPreferredSize(new Dimension(200, 100));
frame.add(jscrlpLabel);
frame.revalidate();
frame.repaint();
try{
System.out.println(path.getText());
HttpURLConnectionExample http = new HttpURLConnectionExample();
int noOfRows = http.setPath(path.getText());
Workbook workbook = Workbook.getWorkbook(new File(path.getText()));
Sheet sheet = workbook.getSheet(0);
Cell cell= sheet.findCell("S. No.");
int col=cell.getColumn();
int row=cell.getRow();
row=row+2;
//System.out.println("row="+row+"col="+col);
for(int i=row;i<noOfRows;i++,row++)
{
int p=http.readFile(col,row);
if(p==1){
JCheckBox cb = new JCheckBox("CheckBox");
JScrollPane jscrlp = new JScrollPane(cb);
jscrlp.setPreferredSize(new Dimension(140, 95));
frame.add(jscrlp);
frame.revalidate();
frame.repaint();
System.out.println("Checkbox created");
}
else if(p==2){
JCheckBox cb1 = new JCheckBox("CheckBox ");
Box box = Box.createVerticalBox();
box.add(cb1);
JScrollPane jScrollPane1 = new JScrollPane(box);
jScrollPane1.setPreferredSize(new Dimension(140, 95));
frame.add(jScrollPane1);
frame.revalidate();
frame.repaint();
System.out.println("Checkbox created with textfield");
}
}
http.getData();
}catch(Exception e){System.out.println("Exception is "+e);}
}
});
//JOptionPane.showMessageDialog(null, "Done", "Alert", WIDTH);
JCheckBox a = new JCheckBox("A");
JCheckBox b = new JCheckBox("B");
JLabel label = new JLabel("Option");
Box box = Box.createVerticalBox();
box.add(label);
box.add(a);
box.add(b);
JScrollPane jscrlpBox = new JScrollPane(box);
jscrlpBox.setPreferredSize(new Dimension(240, 150));
//f.add(jscrlpLabel);
frame.add(jscrlpBox);
frame.setVisible(true);
}
}