Here is my code.

import javax.swing.table.*;
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import java.awt.geom.*;
import java.util.Calendar;

public class Salary_report extends JFrame implements ActionListener
{
   
    Vector data;
    JTable table;
    JLabel banner;	
    ImageIcon images;
    Container c;
    Employee_report f1;
    JButton print;
    String s,days,basic,pf,hra,esi,bonus,advance,allowance,loan,incentive,dother,da,eother,gross,ded,net,leave;
    double ge,td,np,l,l1;
    public Salary_report(Employee_report f1)
    {
       	c=getContentPane();
	c.setLayout(null);
	setResizable(false);
	setTitle("Employee Salary Report");
	setBounds(250,50,700,750);

 	WindowShow.setNativeLookAndFeel();

	s=f1.ename.getSelectedItem().toString();
	basic=f1.txtbsalary.getText();
	pf=f1.txtpf.getText();
	hra=f1.txthra.getText();
	esi=f1.txtesi.getText();
	bonus=f1.txtbonus.getText();
	advance=f1.txtadv.getText();
	allowance=f1.txtsall.getText();
	loan=f1.txtploan.getText();
	incentive=f1.txtinc.getText();
	dother=f1.txtoth.getText();
	da=f1.txtda.getText();
	eother=f1.txtoth1.getText();
	l=Double.parseDouble(f1.txtleave.getText());
	if(l<=1)
	{
		leave="0";
	}	
	else
	{
		Calendar calendar = Calendar.getInstance();
       		int year = calendar.get(Calendar.YEAR);
        	int month = calendar.get(Calendar.MONTH - 1);
        	int date = 1;
        	calendar.set(year, month, date);
        	int day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        	l1=(Double.parseDouble(basic)/day)*(l-1);
		leave=Double.toString(Math.round(l1));	
		days=Integer.toString(day);
	}
	

ge=Double.parseDouble(basic)+Double.parseDouble(hra)+Double.parseDouble(bonus)+Double.parseDouble(allowance)+Double.parseDouble(incentive)+Double.parseDouble(da)+Double.parseDou

ble(eother);
	gross=Double.toString(ge);
	td=Double.parseDouble(pf)+Double.parseDouble(esi)+Double.parseDouble(advance)+Double.parseDouble(loan)+Double.parseDouble(dother)+Double.parseDouble(leave);
	ded=Double.toString(td);
	np=ge-td;
	net=Double.toString(np);
	

	data = createData();
	print=new JButton("Print");
	print.setBounds(300,550,100,20);
	c.add(print);
	print.addActionListener(this);
	
	SplitCellTableModel model = new SplitCellTableModel();
        table = new JTable(model);
        table.getColumnModel().getColumn(0).setCellEditor(new SplitTableCellEditor());
        table.getColumnModel().getColumn(1).setCellEditor(new SplitTableCellEditor());
        table.getColumnModel().getColumn(0).setCellRenderer(new SplitTableCellRenderer());
        table.getColumnModel().getColumn(1).setCellRenderer(new SplitTableCellRenderer());
	
        JScrollPane scroller = new JScrollPane(table);
	
        if(f1.cname.getSelectedItem().toString().equals("Teamwork Architecture"))
        	images=new ImageIcon("TWA.jpg");
	else if(f1.cname.getSelectedItem().toString().equals("Teamwork Techno Solutions"))
        	images=new ImageIcon("TWT.jpg");
	banner=new JLabel();
	banner.setIcon(images);
	banner.setBounds(60,50,600,150);
	c.add(banner,BorderLayout.NORTH);
	
	
	scroller.setBounds(60,250,600,260);
	c.add(scroller);	
    }

    public void actionPerformed(ActionEvent ae)
    {
		String str=ae.getActionCommand();
		if(str.equalsIgnoreCase("Print"))
		{	
			print.setVisible(false);
			PrintableDocument.printComponent(this);
		}
    } 
    public Vector createData()
    {
        Vector result = new Vector();
	Vector rec = new Vector();
        Object[] value = new Object[] {"Employee Name",s};
        rec.add(value);
        value = new Object[] {"Total Days",days};
        rec.add(value);
        result.add(rec);

       	rec = new Vector();
        value = new Object[] {"", ""};
        rec.add(value);
	value = new Object[] {"", ""};
        rec.add(value);
        result.add(rec);

	rec = new Vector();
        value = new Object[] {"Earnings", ""};
        rec.add(value);
        value = new Object[] {"Deductions", ""};
        rec.add(value);
        result.add(rec);
        
	
	rec = new Vector();
        value = new Object[] {"", ""};
        rec.add(value);							
        rec.add(value);
        result.add(rec);

	rec = new Vector();
        value = new Object[] {"Basic",basic};
        rec.add(value);
        value = new Object[] {"PF",pf};
        rec.add(value);
        result.add(rec);
       

	rec = new Vector();
        value = new Object[] {"HRA",hra};
        rec.add(value);
        value = new Object[] {"ESI",esi};
        rec.add(value);
        result.add(rec);
       
	rec = new Vector();
        value = new Object[] {"Bonus",bonus};
        rec.add(value);
        value = new Object[] {"Salary Advance",advance};
        rec.add(value);
        result.add(rec);
       

	rec = new Vector();
        value = new Object[] {"Special Allowance",allowance};
        rec.add(value);
        value = new Object[] {"Personal Loan",loan};
        rec.add(value);
        result.add(rec);
      

	rec = new Vector();
        value = new Object[] {"Incentive",incentive};
        rec.add(value);
	value = new Object[] {"Others",dother};
        rec.add(value);
        result.add(rec);

	rec = new Vector();
        value = new Object[] {"DA",da};
        rec.add(value);
	value = new Object[] {"Leave",leave};
        rec.add(value);
        result.add(rec);
	
	rec = new Vector();
        value = new Object[] {"Others",eother};
        rec.add(value);
	value = new Object[] {"", ""};
        rec.add(value);
        result.add(rec);

	rec = new Vector();
        value = new Object[] {"", ""};
        rec.add(value);
	value = new Object[] {"", ""};
        rec.add(value);
        result.add(rec);
	
        rec = new Vector();
        value = new Object[] {"Gross Earnings(A)",gross};
        rec.add(value);
	value = new Object[] {"Total Deductions(B)",ded};
        rec.add(value);
        result.add(rec);

	rec = new Vector();
        value = new Object[] {"Net Pay (A)-(B)",net};
        rec.add(value);
	value = new Object[] {"", ""};
        rec.add(value);
        result.add(rec);
        return result;
    }
 
    
public class SplitCellTableModel extends DefaultTableModel
{
    public SplitCellTableModel()
    {
    }
 
    public int getRowCount()
    {
        return data.size();
    }
 
    public int getColumnCount()
    {
        return 2;
    }
 
    public String getColumnName(int col)
    {
        if (col == 0)
            return " ";
        else
            return "Date";
    }
 
    public Object getValueAt(int row, int col)
    {
        Vector rec = (Vector)data.get(row);
        return rec.get(col);
    }
 
    public Vector getDataVector()
    {
        return data;
    }
 
    public boolean isCellEditable(int row, int col)
    {
        return false;
    }
 
    public void setValueAt(Object value, int row, int col)
    {
        Vector rec = (Vector)data.get(row);
        rec.setElementAt(value, col);
    }
}
 
 

public class SplitTableCellEditor extends AbstractCellEditor implements TableCellEditor
{
    JPanel editingPanel;
    JTextField leftTextField;
    JTextField rightTextField;
 
    public SplitTableCellEditor()
    {
        super();
        editingPanel = new JPanel();
        editingPanel.setLayout(new GridLayout(1, 2));
        leftTextField = new JTextField();
        editingPanel.add(leftTextField);
        rightTextField = new JTextField();
        editingPanel.add(rightTextField);
    }
 
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowIndex, int colIndex)
    {
        Object[] splitVal = (Object[])value; // cast to array of Object
        if (splitVal != null)
        {
            String leftStr = (String)splitVal[0];
            String rightStr = (String)splitVal[1];
            leftTextField.setText(leftStr == null ? "" : leftStr);
            rightTextField.setText(rightStr == null ? "" : rightStr);
        }
        else
        {
            leftTextField.setText("");
            rightTextField.setText("");
        }
        return editingPanel;
    }
 
    public Object getCellEditorValue()
    {
        Object[] value = new Object[] {leftTextField.getText(), rightTextField.getText()};
        return value;
    }
}
 
 

public class SplitTableCellRenderer implements TableCellRenderer
{
    JPanel rendererPanel;
    JLabel leftLabel;
    JLabel rightLabel;
 
    public SplitTableCellRenderer()
    {
        super();
 
        rendererPanel = new JPanel();
        rendererPanel.setLayout(new GridLayout(1, 2));
        leftLabel = new JLabel("Adfasdf");
        leftLabel.setOpaque(true);
        leftLabel.setBackground(Color.white);
        rendererPanel.add(leftLabel);
        rightLabel = new JLabel("adsfsdf");
        rightLabel.setOpaque(true);
        rightLabel.setBackground(Color.white);
        rendererPanel.add(rightLabel);
    }
 
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col)
    {
        Object[] splitVal = (Object[])value; // cast to array of Object
        if (splitVal != null)
        {
            String leftStr = (String)splitVal[0];
            String rightStr = (String)splitVal[1];
            leftLabel.setText(leftStr == null ? "" : leftStr);
            rightLabel.setText(rightStr == null ? "" : rightStr);
        }
        else
        {
            leftLabel.setText("");
            rightLabel.setText("");
        }
        return rendererPanel;
    }
}
 
}

My output is pdf file. I am attached the pdf file.

My pdf file contain half output. the remaining page is not show. Please tell me the solution as soon as possible.

Would you like a blueberry pie with that solution?

Can you please be a little more specific? What is your code doing? What do you want it to do?

do you see my attached pdf file. that contain only half of the page result. That means the size is very large. Half of the Jtable content is displayed. I want full Jtable with Image.

You can try this then:

JScrollPane scrollTable = new JScrollPane(table);

And then add the scrollTable to the panel or the JFrame.

already i am add my table to jscrollpane. in printing time(i.e) If i click print button the current page is print. but some content is loss. I want full jtable content. please help me

I don't see anything in your code having to do with printing (other than the button). The problem must be in your PrintableDocument class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.