Use a JTable
for tabular data! See How to Use Tables for details.
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.MissingFormatArgumentException;
import javax.swing.*;
import javax.swing.border.Border;
public class MainReport extends JApplet {
String[] colName = new String[] { "Date", "Account.No", "Description",
"Deposit", "Withdraw" };
// here is my input of String Array.
String a[][] = new String[][] {
{ "13/12/2013", "101", "AlphaSoftInfotekNashik", "3000", "0" },
{ "15/12/2013", "102", "Bank Ladger 2 xxxxxxxxxxxxx", "5000", "0" },
{ "16/12/2013", "103", "Accout Closing with Details", "800", "0" } };
StringBuilder sb = new StringBuilder();
final String Header = "%s %85s%n%n%s %10s%n";
// final String HRule ="";
final String format = "|%1$-30s|%2$-30s|%3$-30s|%4$-30s|%5$-35s";
final String NumColF = "";
String cformat = "%20s";
String format1 = "%20s";
String s1 = "%61s";// for spillover text
String s2 = "%10s";
int i, j, k;
int Position = 0;
boolean flag = false;
String a1, a2;
Container c;
JTable outputArea;
public static final int LINES = 10;
public static final int CHAR_PER_LINE = 40;
JButton b;
public void init() {
c = getContentPane();
c.setLayout(new FlowLayout());
outputArea = new JTable(a, colName);
//outputArea.setLocation(100, 100); // pointless when using layout managers..
Border border = BorderFactory.createLineBorder(Color.RED);
outputArea.setBorder(BorderFactory.createCompoundBorder(border,BorderFactory.createEmptyBorder(10, 10, 10, 10)));
c.add(outputArea);
b = new JButton("Show Report");
c.add(b);
}
}