Home Answers Viewqa Java-Beginners Java Print the all components

 
 


Pushpa Sheela
Java Print the all components
0 Answer(s)      2 years and 7 months ago
Posted in : Java Beginners

This is my code. Please tell me the solutions

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;
}

}

}

If i click print button then my current window is print in a paper.

The paper contain only half of the output. But i want full screen output.

Please tell me the solutions

View Answers









Related Pages:
Java Print the all components
Java Print the all components  This is my code. Please tell me...; ImageIcon images; Container c; Employee_report f1; JButton print; String s,days...(td); np=ge-td; net=Double.toString(np); data = createData(); print=new
print
print  How to print JFrame All Componant?   Please visit the following link: http://www.roseindia.net/java/example/java/swing/Print.shtml
Print
Print  In system.out.println,what meant ln..?   System: It is a class made available by Java to let you manipulate various operating system... into the stream and, as opposed to print() method, gets you to the new line after the text
Introduction to Components
own components The predefined Java components are adequate for all normal... Java NotesIntroduction to Components Swing Components You can draw... these components are: Java has already defined them
JDBC Components
JDBC Components    JDBC stands for Java... is not connected then it throws the exception and print the message. Java Database Connectivity... in the java.sql package for Java applications to communicate with databases. Mostly
JSF Components
in between client requests. These components are manipulated on the sever in java code...JSF Components      Components in JSF are elements like text box, button, table etc.. that are used
Chapter 2. Design, build and test web components
components Prev  Part I. ... Servlet filters are pluggable Web components that allow us to implement pre-processing... Servlet filters are small Web components that intercept requests and responses
Components
Java NotesComponents Components (also known as "widgets") are the basic.... Vanilla Java. The most important components to learn for simple..., ... Components are placed in a container (eg, JPanel). The visual
JFrame Components Printing - Swing AWT
JFrame Components Printing  hi sir i am doing a project so i am working in netbeans i have to print a JFrame it contains Labels and few... link: http://www.roseindia.net/java/example/java/swing/Print.shtml Hope
Summary - Basic GUI Components
Java: Summary - Basic GUI Components Swing API provides lots components for crating the GUI for Java Swing applications. In this section we...) JList Let's see all these components in detail. Most components
JFrame Components Printing - Swing AWT
JFrame Components Printing  hi sir thanks a lot for your reply... but i go through the link that you have specified http://www.roseindia.net/java/example/java/swing/Print.shtml and downloaded the codes and compiled it got
JFrame components printing - Swing AWT
JFrame components printing  hi sir thanks a lot for your reply... but i go through the link that you have specified http://www.roseindia.net/java/example/java/swing/Print.shtml and downloaded the codes and compiled it got
JFrame components printing - Swing AWT
JFrame components printing  hi sir thanks a lot for your reply... but i go through the link that you have specified http://www.roseindia.net/java/example/java/swing/Print.shtml and downloaded the codes and compiled it got
how to print all colors using awt
how to print all colors using awt  how to print all colors using awt
Reading Files and Print - Java Beginners
the Particular name "School A" and print all contents in the file(s). I give... where more than one student are from the same school it should print all...Reading Files and Print  Hey Guys, I'm a beginner to java and I
Placing components on each other - Java Tutorials
Placing components on each other 2002-02-15 The Java Specialists' Newsletter [Issue 041] - Placing components on each other Author: Dr. Heinz M. Kabutz.... Welcome to the 41th (or is it 41st?) edition of The Java(tm) Specialists
Test and debug enterprise components
Test and debug enterprise components... components Generating EJB deployment code from the workbench.... Click Select all to automatically select all of the enterprise beans
Serializing GUI Components Across Network - tutorial
Serializing GUI Components Across Network 2001-03-14 The Java Specialists' Newsletter [Issue 013a] - Serializing GUI Components Across Network Author... via email or RSS. Welcome to the 13th issue of "The Java(tm) Specialists
Create Layout Components in a Grid in Java
Create Layout Components in a Grid in Java   ... layout components with the help of grid in Java Swing. The grid layout provides... is the vertical gap between components. This constructor takes all the integer value
Print the URL of a URLConnection
Print the URL of a URLConnection   ... of the program in which first of all we establish a connection then display...:\roseindia>javac printURLConnection.java C:\roseindia>java
how to print all possible combination that sum to zero??
how to print all possible combination that sum to zero??  Ã?Â.... Print all possible combinations that sum to zero Example Enter a num : 7 1... each of the digits so that the resultant sum is zero. Print all posible
ALL command - SQL
ALL Command in Java & SQL  Nee all commands in Java.  Dear Manoj, I didn't get u what do u mean by all command. could u please... THAT ARE USED IN JAVA ARE GIVEN BELOW 1.javac c:\ javac classname.java
JDBC Components
JDBC Components    Jdbc has following components-- 1.  JDBC API      Using  JDBC API ,frontend java applications... to connect java application with 'JDBC Driver'.' Driver Manager'
what are the components of java platform ?
what are the components of java platform ?  what are the components of java platform ? plz if any1 perfectly know help me to override my conflicts.plz explain briefly
Product Components of JDBC
Product Components of  JDBC       JDBC has four Components: 1. The JDBC API. 2... the Java programming language. The API technology provides the industrial standard
Declare components
Java NotesWhere to declare components Components are typically declared in one of several places: Field variables Some components should be declared...). This is the appropriate place to declare components which must be referenced after
Print Screen Using Java Swing
Print Screen Using Java Swing       In this section, you will learn how to print in java swing. The printable that is passed to setPrintable must have a print method
print only Form Fillup Contents through Text File - Java Beginners
print only Form Fillup Contents through Text File   Hello Sir ,I have Designed Employee Details Form using java swing components Now i want to print contents which is filled by employee,How i can Print it,and also i want print
AWT Components
AWT Components       The class component is extended by all the AWT components. More of the codes can be put to this class to design lot of AWT components. Most of the AWT
To print initials
To print initials  import java.util.Scanner; class initials { String a ; int e ; char f ; int b ; int c ; char d; Scanner sc = new... link: http://www.roseindia.net/tutorial/java/core/printInitials.html
How to print this in java?
How to print pattern in Java?  How to print a particular pattern in Java...;  How to print this in java
Chapter 3. Develop clients that access the enterprise components
; Chapter 3. Develop clients that access the enterprise components Implement Java clients calling EJBs Application client projects... is used to contain a full-function client Java application (non Web-based
viewing the ms word in print layout from jsp - Java Beginners
viewing the ms word in print layout from jsp  Hi all, I am trying to export ms word from jsp in print layout format.I used the code... is to open in print layout format. If u have any code for converting into print
Print Form - Java Beginners
Print Form  Hello Sir I have Created Admission Form when user fills data and submit that data to access database,then when i Click on PRINT Button I want to get Print of that forms Contents,How I can Do it with JAVA SWING,plz
Java Print Dialog
Java Print Dialog  Using java.awt.print.PrinterJob and javax.print.attribute.PrintRequestAttributeSet. I call .printDialog(ps) and the standard print dialog is displayed with options preset to my chosen attributes. Now I can
how to print - Java Beginners
how to print  how to print something on console without using System.out.print() method ?  Hi Friend, You can use PrintWriter to write anything on the console. import java.io.*; public class Print{ public static
print rectangle pattern in java
print rectangle pattern in java  * * * * * * * how to generate this pattern in java??   Hi friend try this code may this will helpful for you public class PrintRectangle { public static void main
print a rectangle - Java Beginners
print a rectangle  how do I print a rectangleof stars in java using simple while loop?Assuming that the length n width of the rectangle is given.  Hi friend, I am sending running code. import java.io.
java awt components - Java Beginners
java awt components  how to make the the button being active at a time..? ie two or more buttons gets activated by click at a time
Print in a long paper - Java Beginners
Print in a long paper  how to print text in long paper?? each print text, printer stops. not continue until the paper print out. Thanks
Print the following format
Print the following format  how to print the following format given string "00401121" in java 0-** 1-* 2-* 3- 4
Chapter 2. Design, build and test web components
all the existing Java projects from the workbench...; Chapter 2. Design, build and test web components Design, develop and test Java Servlets, filters and listeners
noise during print screen
noise during print screen  hi there, i have a java program which can print screen every 1 seconds... but during the print screen, the image seems will have some noise and ends up half page of the image will be black screen
Flex Custom Components
. You can also collect all your utility Custom components and use it multiple... Custom Components Flex ships with number of readymade components. But many times we need components, which can provide custom functionality fulfilling
print hello n hi
print hello n hi  how to write a java program that prints "hello" 5 times, "hi" 1 time n again "hello" 4 times..?? do reply
Chapter 1. Design, build and test reusable enterprise components
; Chapter 1. Design, build and test reusable enterprise components.... It is deployed in a standard Java archive (JAR) file. An EJB module can... no conversational state. All instances of a stateless session bean
A Program To Print A Equilateral Triangle
A Program To Print A Equilateral Triangle  Write A program to Print Following In Java : 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
How to print the following pattern in java?
How to print the following pattern in java?  How to print the following pattern in java? he he is he is going he is going in   import java.io.*; class StringPattern { public static void main(String[] args
Java AWT Components
Java AWT Components      ... components available in the Java AWT package for developing user interface for your program. Following some components of Java AWT are explained :  Labels
how to print pdf format
how to print pdf format  Hi every body iam doing school project iam using backend as oracle front end java .how to print student marks list /attendence in pdf format. please help me. thanks in advance.   Here

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.