응용 프로그램은 정보를 가져 와서 데이터베이스에서 양식을 채우거나이 양식에서 데이터베이스에 쓸 수 있습니다. 지금 당장 Netbeans를 사용하여 MySQL 테스트 서버에 접속할 수 있습니다.프린터에 JFrame 정보 보내기
내가 겪고있는 문제는 사무실에서 현재 사용하고있는 손으로 작성한 양식과 일치시키기 위해 데이터베이스가 아닌 테이블과 같은 형식으로 데이터베이스에서 얻은 정보를 인쇄해야한다는 것입니다. 사용자가 볼 수 있도록 화면에 배치 된 것처럼 전체 JFrame 또는 JFrame의 모든 내용을 인쇄하는 방법이 있습니까?
내가 지금까지 본 모든 것은 화면 영역 (텍스트 상자)을 인쇄하거나 테이블을 통해 인쇄합니다.
응용 프로그램은 모든 것이 완료되고 완료 될 때 Linux와 Windows 용으로 컴파일됩니다.
코드 :. JTable
API에서
package Information;
import java.awt.print.*;
import java.awt.*;
import javax.swing.*;
public class HATDB extends javax.swing.JFrame implements Printable {
JFrame frameToPrint;
/** Creates new form HATDB */
public HATDB() {
}
@Override
public int print(Graphics g, PageFormat pf, int page) throws
PrinterException {
if (page > 0) { /* We have only one page, and 'page' is zero-based */
return NO_SUCH_PAGE;
}
/* User (0,0) is typically outside the imageable area, so we must
* translate by the X and Y values in the PageFormat to avoid clipping
*/
Graphics2D g2d = (Graphics2D) g;
g2d.translate(pf.getImageableX(), pf.getImageableY());
/* Now print the window and its visible contents */
frameToPrint.printAll(g);
/* tell the caller that this page is part of the printed document */
return PAGE_EXISTS;
}
public HATDB(JFrame f) {
frameToPrint = f;
}
private void OK_ButtonActionPerformed(java.awt.event.ActionEvent evt) {
PrinterJob job = PrinterJob.getPrinterJob();
//job.setPrintable();
boolean ok = job.printDialog();
if (ok) {
try {
job.print();
} catch (PrinterException ex) {
ex.printStackTrace(System.err);
}
}
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
JFrame f = new JFrame("Print UI Example");
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new HATDB().setVisible(true);
}
});
}
}
예. 다른 Java 구성 요소를 인쇄하는 것과 비슷한 JFrame을 인쇄 할 수 있지만 예쁜 인쇄물을 만들기 위해 최적화되지 않았습니다. 왜 이런 종류의 문제를 해결하기 위해이 유형의 프로그램이 만들어 졌으므로 JasperReports와 같은보고 도구를 사용하는 것이 좋을까요? –
JasperReports를 사용하는 데 도움이되는 예나 방향이 있습니까? – Friendlyghost89
음 ... Google이 다운되어 있어야한다고 생각하십니까? –