Home Answers Viewqa Swing-AWT Need Help with Java-SWING progrmming

 
 


sreejith
Need Help with Java-SWING progrmming
2 Answer(s)      4 years and 9 months ago
Posted in : Swing AWT

View Answers

September 1, 2008 at 10:23 AM


Hi Sreejith

check this source(easy way).
package library.code;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumn;

@SuppressWarnings("serial")
public class ListIssueBook extends JInternalFrame implements Printable{

private JPanel headPanel,buttonPanel,tablePanel;
private JLabel headLabel;
private JButton exitButton,printButton;
private Container container;
private TableStructure tabStructure;
private JTable table;
private JScrollPane scrollPane;
private TableColumn column;
String issueQuery;
public ListIssueBook(){
container = getContentPane();
headLabel = new JLabel("List of Issued Book");
headLabel.setFont(new Font("Arial",Font.BOLD,16));
headPanel = new JPanel();
headPanel.add(headLabel);
container.add("North",headPanel);

issueQuery = "SELECT i.EmpId,b.BookID,b.Category,b.Name,b.Author,b.Publication,i.status FROM Books b, Issues i WHERE b.status = 'Issue' AND b.BookID = I.BookId AND i.status = 'Pending' ";
try{
tabStructure = new TableStructure();
tabStructure.setQuery(issueQuery);
}catch(Exception e){

}
table = new JTable(tabStructure);
table.setPreferredScrollableViewportSize(new Dimension(600,200));
scrollPane = new JScrollPane(table);
for(int i=0; i<5; i++){
column = table.getColumnModel().getColumn(i);
if(i == 0)
column.setPreferredWidth(7);
if(i == 1)
column.setPreferredWidth(15);
if(i == 2)
column.setPreferredWidth(25);
if(i == 3)
column.setPreferredWidth(25);
if(i == 4)
column.setPreferredWidth(25);
if(i == 5)
column.setPreferredWidth(7);
}
tablePanel = new JPanel();
tablePanel.setLayout(new BorderLayout());
tablePanel.add(scrollPane,BorderLayout.CENTER);
container.add("Center",tablePanel);

exitButton = new JButton("Exit");
printButton = new JButton("Print");
buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
buttonPanel.add(printButton);
buttonPanel.add(exitButton);
container.add("South",buttonPanel);

setVisible(true);
pack();

exitButton.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent arg0) {
dispose();
}

});

printButton.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent arg0) {
PrinterJob prJob = PrinterJob.getPrinterJob();
prJob.setPrintable(ListIssueBook.this);
if(!prJob.printDialog())
return;
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
prJob.print();
} catch (PrinterException e) {
e.printStackTrace();
}
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}

});
}
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException {
if (pageIndex != 0) return NO_SUCH_PAGE;
Graphics2D graphics2D = (Graphics2D)graphics;
graphics2D.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
getContentPane().paint(graphics2D);
return PAGE_EXISTS;
}
}


Regards
Rajanikant Mishra

September 1, 2008 at 10:26 AM


Hi friend,


Read for more information.


http://www.roseindia.net/java/example/java/swing/Print.shtml


Thanks.









Related Pages:
Need Help with Java-SWING progrmming - Swing AWT
Need Help with Java-SWING progrmming  Hi sir, I am a beginner in java-swing programming. I want to know how we can use the print option with a program in swing. Could you help me with an example? Regards Sreejith 
Need Help To Connect XML as backend in Java-Swing
Need Help To Connect XML as backend in Java-Swing  Seat arrangment swing screenshot I made XML program to connect to swing like this. <?xml... problem is if i click the B1 label it need to change as(occupied-grey colour
jtable in java swing
jtable in java swing  hai friends... i am creating 1 GUI having 1.... It gets filled through program. I need to develop such application. After... in the 3rd column.like way.. Some 1 please help me to develop such application
Java swing
are displayed in the table..I need the source code in java swing...Java swing  If i am login to open my account the textfield,textarea and button are displayed. if i am entering the time of the textfield
Java Swing Tutorials
with the help of Java 2D API.   Data Transfer Swing... components with the help of grid in Java Swing. The grid layout provides... Java Swing Tutorials      
Java swing
Java swing  Design an appliaction for with details such as name,age,DOB,address,qualification and finaly when we click the view details button all types details should be displayed in another View in TextView's..I need the sample
Java swing
Java swing  I create 2 text field f1,f2 and 2 button b1,b2.If i enter some text in the text field and click the button b1 the text field f1 text... f2 text will be shown in another one Messagedialog box.I Need the code
java swing and CSS
java swing and CSS  can css be used in java swing desktop application in different forms for better styles?plzz help
Java Swing Open Browser
Java Swing Open Browser Java provides different methods to develop useful... that will open the specified url on the browser using java swing. This example will really helpful if you need to show the help window for your application. Here, we have
Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which
Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which
Need help
Need help  Dear sir, I have a problem. How to write JSP coding, if a user select a value from drop down list for example department, the another drop.... This name list should get from the database. Please help me. By the way, I'm
Need help with this!
Need help with this!  Can anyone please help me... to a file at all at this time. Any help would be greatly appreciated, thank you... to effectivly end the loop with out the need to break it. for(i=(0); i <
java - Swing AWT
java  i need to set the popup calender button in table column&also set the date in the same table column using core java-swing
Query on Java Swing - Table Cell Issue - Swing AWT
Query on Java Swing - Table Cell Issue  Hi, I have a query on Java Swing. we are using swing in our application, In one of the frame we... unable to show the cursor in the focused cell which is editable. what do I need do
need
need  i need a jsp coding based project plz help me
Date picker in Java Swing
in need of Time Picker just like the Date picker available in java Swing. Kindly... thoroughly . But Sir, I want Time Picker In java swing desktop application..., I want Time Picker In java swing desktop application. In time picker we can
Java Swing code for zoom in and out
Java Swing code for zoom in and out  hi.......... I require a code in java swing for image zoom in and zoom out can u tell me how it can be done or what is the code plz help
java swing - Swing AWT
java swing   Iam developing a java web browser.Actually my code works fine ie. i can load a web page without proxy.But in my place i have only proxy... a proxy or how to make my java web browser to listen to proxy setting??? please help
java swing (jtable)
java swing (jtable)  hii..how to get values of a particular record in jtable from ms access database using java swing in netbeans..?? please help..its urgent..   Here is an example that retrieves the particular record
java swing - Java Beginners
(){ JFrame f = new JFrame("Frame in Java Swing"); f.getContentPane().setLayout(null...java swing  How to set the rang validation on textfield, compare... want to send the selected item in database , how to send , plz help
java - Swing AWT
java  hello sir pls answer..need that urgently
Need Help on JMS - JMS
Need Help on JMS   Hi, In my application i need to create my own ques and my own QueueConnectionFactory..... Plz tell me how to create the same... Any help is appriciated,.. Thanks in advance
java - Swing AWT
java  hi can u say how to create a database for images in oracle and store and retrive images using histogram of that image plz help me its too urgent
Java - Swing AWT
Java  Hello friends, I am developing an desktop application in java & I want to change the default java's symbol on the top & put my own symbol there.. Can Anyone help me
java - Swing AWT
java  how can i link one GUI interface to another?help me pliz  Hi Friend, Do you want to connect two GUI applications? Thanks
Need help with nested queries
Need help with nested queries  Hello, Table1 has "id", "votes" columns. Table2 has "id", "Name" column. I need to retrieve Name and its corresponging Votes. I tried with nested queries but its confusing. Can anyone please help
java - Swing AWT
java  hello sir.. i want to start the project of chat server in java please help me out how to start it?? urgently....  Hi friend, To solve problem to visit this link....... http://www.roseindia.net
java swing - Java Beginners
java swing  hi, I have the jtextfield and jtextarea in the same page. If i enter the text in the textfield ,i need to get the same text in the textarea.how can i get it. please send the sample code for this. I need the code
java swing jdbc - Java Beginners
java swing jdbc  hello, i want to populate the data(ms access) to the jtable component and want to perform some operations on it like add,edit,delete. Again i want to store the updated data to the database. can you help me out
java - Swing AWT
project flw will be there..so.......plzzzzzzzz.....help me & reply me as soon
java - Swing AWT
java  hello..sir.....plzzzzzzz help me to display selected image on JPanel.  Hi Friend, Try the following code: import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import
need help please
need help please  Dear sir, my name is logeswaran. I have a big problem that I can't find the solution for a program. How can I block a user from enter a page second time. Please help me. By the way I'm using Access database
Need Help in Java programming
Need Help in Java programming  Hello. Can someone please help me with writing the following program Java program that gives assignment details such as:assignment number,assignment name,due date,submission date,percentage marks
Threads in Java Swing MVC Application
Threads in Java Swing MVC Application  Hello, I am currently making a Java Swing application, but I am having a lot of trouble with implementing... it to work in the MVC program. Please help me, or point me to some information
need help to create applet
need help to create applet  Can u help me..?? I get a task ...and i dont know how to make it... So I hope that u can help me... Here is the task... If u can help me, then please send it to my email lcfahmi90@yahoo.com http
java - Swing AWT
java  hello friend could you help me modify for me this code such that it can output for me the balance after i have deposited money? import java.awt.*; import javax.swing.*; import java.awt.event.*; class Savings { public
java swing - Java Beginners
java swing  How to upload the image in using java swings. ex- we make a button to browsbutton and savebutton , when we click on the browsbutton , i can brows the image from the computer. plz help soon......... thanx. 
Need help on JAVA JSP
Need help on JAVA JSP  Hi, I have never worked on java and I have... using JAVA JSP). e.g. Tool does not adjust with the resolution of the screen(need to know how I can adjust it based on the cureen system's screen resolution
Need some help urgently
Need some help urgently  Can someone please help me with this below question. I need to write a class for this. If you roll Y standard six-sided dice... need to write a class for this where X and Y are passed as parameter. If someone
hello there i need help
i am a beginner, and aside from that i am really eager to learn java please help me with the codes and please explain to me how it works. i only need to use...hello there i need help  : i need to do a program like
Need help with console program?
Need help with console program?  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). thanks in advance.   Here is an example that repeatedly
Need Help With This Scenario
Need Help With This Scenario  The bonnet of a car is opened to determine if there is anything wrong with the engine. Firstly, the radiator water is checked. If the radiator water is below the minimum indicator level
Need Help With This Scenario
Need Help With This Scenario  The bonnet of a car is opened to determine if there is anything wrong with the engine. Firstly, the radiator water is checked. If the radiator water is below the minimum indicator level
Need Help - Java Beginners
Need Help  Hello Sir, Am a beginner of Java. Also i did course... projects in Java as well as J2EE... Can u help me and guide to do a project.../reference/tutorials/ http://netbeans.org/kb/trails/java-ee.html http
i need a help in this please
i need a help in this please  The factorial of a nonnegative integer n is written n! (pronounced â?? n factorialâ??) and is defined as follows: n!=n . (n-1) . (n-2) . .... . 1 (for values of n greater than or equal to 1) and n!=1
Need Help on the script
Need Help on the script  hello there, My name is Femi and am a web developer using php. am working on a project. and am having some difficulties. i dont know if you can help me out with it. The platform am building will receive
need help - Java Beginners
need help  Need help in programming in Java  Simple java program that will show the output within quotes using system.out.println();DISPLAYING OUPUT " * " ," *** " ........I used System.out.print
I have need to help
I have need to help  Write a program that, for four points A, B, C and P, draws a triangle formed by ABC and a small cross showing the position of P; and displays a line of text indicating which of the following three cases
Need help - Java Beginners
Need help   To Write a Java program that asks the users to enter a m * n matrix of integers, m and n being the number of rows and columns...; Hi Friend, Please try the following code. We hope that this code will help

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.